var bracketCtrls = angular.module('bracketCtrls', []);
var SUCCESS="0000";
var time;//定时器

function checkRole(uri,id){
    window.clearTimeout(time);

    if(accessControllers.indexOf(uri) == -1){
        location.href = BasePath + "/#/main";
        return true;
    }else{

        $("#main").removeClass("active");
        $(".nav-parent").removeClass("active nav-active");
        $('#'+id).attr("class","nav-parent active nav-active");
        if(minMenu == "0"){
            $(".children").hide();
            $('#'+id+'Children').show();
        }
        $(window).scrollTop(0);
        return false;
    }
}
function checkElement(ele){
    return accessElement.indexOf(ele) != -1;
}
/**
 * 攻击端、靶机心跳器
 * @param uri
 */
function nowState(uri){
    window.clearTimeout(time);
    var ips="";
    for ( var i = 0; i < $('.wi-sunset').length; i++) {
        ips = ips + $('.wi-sunset').eq(i).attr('id') + ",";
    }
    if(ips != ""){
        ips = ips.substring(0, ips.length-1).replace(/-/g,'.');
        time=window.setInterval(myInterval,30000);//1000为1秒钟
        function myInterval(){
            $.ajax({
                type : "POST",
                url : BasePath + uri,
                data : {
                    'ips' : ips
                },
                dataType : "json",
                success : function(data) {
                    if (data.retCode == SUCCESS) {
                        var list = data.result;
                        for ( var i = 0; i < list.length; i++){
                            $('#'+list[i].ip.replace(/\./g,'-')).attr("style",list[i].state);
                        }
                    }
                }
            });
        }
    }
}
/**
 * 退出系统
 */
bracketCtrls.controller('wholeCtrl', [ '$scope', function($scope) {
    window.clearTimeout(time);
    $scope.logout = function() {
        sessionStorage.clear();
        location.href = BasePath + "/logout.do";
    };
} ]);
/**
 * 首页
 */
bracketCtrls.controller('main', [ '$scope', function($scope) {
    window.clearTimeout(time);
    $(window).scrollTop(0);
    $('#main').attr("class","active");
    $(".nav-parent").removeClass("active nav-active");
    if(minMenu == "0"){
        $(".children").hide();
    }
    $('#contentpanel4main').attr("style","display:block;");  //样式显示
    if(checkElement('quantityStatistics,')){
        $('#welcome').hide();
        $('#row1').attr("style","display:block;");  //样式显示
        if(!checkElement('detectionRate,')){
            $('#row2-1').attr("class","col-sm-12 col-md-12");
            $('#row2-2').attr("style","display:none;");  //样式隐藏
        }
        $('#row2').attr("style","display:block;");
        $.ajax({
            type : "POST",
            url : BasePath + "/main/query.do",
            dataType : "json",
            async : false,
            success : function(data) {
                $('#usercount').html('<span>'+data.用户+'</span>');
                $('#useroff').html('<span>'+data.未注销用户+'</span>');
                $('#useron').html('<span>'+data.注销用户+'</span>');
                $('#samplecount').html('<span>'+data.样本+'</span>');
                $('#samplevirus').html('<span>'+data.病毒样本+'</span>');
                $('#samplecmcc').html('<span>'+data.移动互联网疑似病毒样本+'</span>');
                $('#samplebankcount').html('<span>'+data.样本库+'</span>');
                $('#samplebankvirus').html('<span>'+data.病毒样本库+'</span>');
                $('#samplebankcmcc').html('<span>'+data.移动互联网疑似病毒样本库+'</span>');
                $('#targetcount').html('<span>'+data.靶机+'</span>');
                $('#targeton').html('<span>'+data.在线靶机+'</span>');
                $('#targetoff').html('<span>'+data.离线靶机+'</span>');
                $('#taskcount').html('<span>'+data.任务+'</span>');
                //echarts饼图
                var chart1 = echarts.init(document.getElementById('main1')); //取得要显示该饼图DIV的id
                var option1 = {
                    title : {
                        text: '拨测任务数量分布图',
                        subtext: '根据任务状态统计相应任务数量',
                        x:'center'
                    },
                    tooltip : {
                        trigger: 'item',
                        formatter: "{a} <br/>{b} : {c} ({d}%)"
                    },
                    legend: {
                        orient: 'vertical',
                        left: 'left',
                        data: ['初始任务','正在下发任务','下发失败任务','已下发任务','就绪任务','进行中任务','完成任务','撤销任务']
                    },
                    series : [
                        {
                            name: '任务类型',
                            type: 'pie',
                            radius : '55%',
                            center: ['50%', '60%'],
                            data:[
                                {value:data.初始任务, name:'初始任务'},
                                {value:data.正在下发任务, name:'正在下发任务'},
                                {value:data.下发失败任务, name:'下发失败任务'},
                                {value:data.已下发任务, name:'已下发任务'},
                                {value:data.就绪任务, name:'就绪任务'},
                                {value:data.进行中任务, name:'进行中任务'},
                                {value:data.完成任务, name:'完成任务'},
                                {value:data.撤销任务, name:'撤销任务'}
                            ],
                            itemStyle: {
                                emphasis: {
                                    shadowBlur: 10,
                                    shadowOffsetX: 0,
                                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                                }
                            }
                        }
                    ]
                };
                chart1.setOption(option1); //执行该饼图并显示
            }
        });
    }
    if(checkElement('detectionRate,')){
        $('#welcome').hide();
        if(!checkElement('quantityStatistics,')){
            $('#row2-2').attr("class","col-sm-12 col-md-12");
            $('#row2-1').attr("style","display:none;");
            $('#row2').attr("style","display:block;");
        }
        $.ajax({
            type : "POST",
            url : BasePath + "/main/queryPercent.do?operator="+operator,
            date: {},
            dataType : "json",
            async : false,
            success : function(data) {
                var chart2 = echarts.init(document.getElementById('main2'));
                var option2 ={
                    title: {
                        text: '运营商平均检测率分布图',
                        subtext: '根据省份统计该运营商平均检测率(百分比)',
                        left: 'center'
                    },
                    tooltip: {
                        trigger: 'item'
                    },
                    visualMap: {
                        min: 0,
                        max: 100,
                        left: 'left',
                        top: 'bottom',
                        text: ['高','低'],           // 文本，默认为数值文本
                        calculable: true
                    },
                    toolbox: {
                        show: true,
                        orient: 'vertical',
                        left: 'right',
                        top: 'center',
                        feature: {
                            dataView: {readOnly: false}
                        }
                    },
                    series: [
                        {
                            name: name,
                            type: 'map',
                            mapType: 'china',
                            roam: false,
                            label: {
                                normal: {
                                    show: true
                                },
                                emphasis: {
                                    show: true
                                }
                            },
                            data:data.listTTaskresult,
                        }
                    ]
                };
                chart2.setOption(option2);
            }
        });
        //echarts地图，选择地图上面的下拉框之后
        var operator = 0;
        var name = '平均检测率(百分比)';
        $('#operator').change(function(){
            operator=$('#operator').val();
            $.ajax({
                type : "POST",
                url : BasePath + "/main/queryPercent.do?operator="+operator,
                date: {},
                dataType : "json",
                async : false,
                success : function(data) {
                    var chart2 = echarts.init(document.getElementById('main2')); //取得要显示该地图DIV的id
                    var option2 ={
                        title: {
                            text: '运营商平均检测率分布图',
                            subtext: '根据省份统计该运营商平均检测率(百分比)',
                            left: 'center'
                        },
                        tooltip: {
                            trigger: 'item'
                        },
                        visualMap: {
                            min: 0,
                            max: 100,
                            left: 'left',
                            top: 'bottom',
                            text: ['高','低'],           // 文本，默认为数值文本
                            calculable: true
                        },
                        toolbox: {
                            show: true,
                            orient: 'vertical',
                            left: 'right',
                            top: 'center',
                            feature: {
                                dataView: {readOnly: false}
                            }
                        },
                        series: [
                            {
                                name: name,        //地图标题名字
                                type: 'map',
                                mapType: 'china',
                                roam: false,
                                label: {
                                    normal: {
                                        show: true
                                    },
                                    emphasis: {
                                        show: true
                                    }
                                },
                                data:data.listTTaskresult,   //显示查询出的数据
                            }
                        ]
                    };
                    chart2.setOption(option2); //执行该地图并显示
                }
            });
        });
    }
    if(checkElement('myselfTask,')){
        $('#row3').attr("style","display:block;");  //样式显示
        $.ajax({
            type : "POST",
            url : BasePath + "/main/queryUserTask.do",
            date: {},
            dataType : "json",
            async : false,
            success : function(data) {
                //echarts饼图
                var chart3 = echarts.init(document.getElementById('main3')); //取得要显示该饼图DIV的id
                var option3 = {
                    title : {
                        text: '个人任务数量分布图',
                        subtext: '根据任务状态统计相应任务数量',
                        x:'center'
                    },
                    tooltip : {
                        trigger: 'item',
                        formatter: "{a} <br/>{b} : {c} ({d}%)"
                    },
                    legend: {
                        orient: 'vertical',
                        left: 'left',
                        data: ['初始任务','正在下发任务','下发失败任务','已下发任务','就绪任务','进行中任务','完成任务','撤销任务']
                    },
                    series : [
                        {
                            name: '任务类型',
                            type: 'pie',
                            radius : '55%',
                            center: ['50%', '60%'],
                            data:[
                                {value:data.初始任务, name:'初始任务'},
                                {value:data.正在下发任务, name:'正在下发任务'},
                                {value:data.下发失败任务, name:'下发失败任务'},
                                {value:data.已下发任务, name:'已下发任务'},
                                {value:data.就绪任务, name:'就绪任务'},
                                {value:data.进行中任务, name:'进行中任务'},
                                {value:data.完成任务, name:'完成任务'},
                                {value:data.撤销任务, name:'撤销任务'}
                            ],
                            itemStyle: {
                                emphasis: {
                                    shadowBlur: 10,
                                    shadowOffsetX: 0,
                                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                                }
                            }
                        }
                    ]
                };
                chart3.setOption(option3);  //执行该饼图并显示
            }
        });
    }

    /**
     *
     */

    if(checkElement('myCompanyTask,')){
        $('#row3').attr("style","display:block;");  //样式显示
        $.ajax({
            type : "POST",
            url : BasePath + "/main/queryCompanyTask.do",
            date: {},
            dataType : "json",
            async : false,
            success : function(data) {
                //echarts饼图
                var chart3 = echarts.init(document.getElementById('main3')); //取得要显示该饼图DIV的id
                var option3 = {
                    title : {
                        text: '企业任务数量分布图',
                        subtext: '根据任务状态统计相应任务数量',
                        x:'center'
                    },
                    tooltip : {
                        trigger: 'item',
                        formatter: "{a} <br/>{b} : {c} ({d}%)"
                    },
                    legend: {
                        orient: 'vertical',
                        left: 'left',
                        data: ['初始任务','正在下发任务','下发失败任务','已下发任务','就绪任务','进行中任务','完成任务','撤销任务']
                    },
                    series : [
                        {
                            name: '任务类型',
                            type: 'pie',
                            radius : '55%',
                            center: ['50%', '60%'],
                            data:[
                                {value:data.初始任务, name:'初始任务'},
                                {value:data.正在下发任务, name:'正在下发任务'},
                                {value:data.下发失败任务, name:'下发失败任务'},
                                {value:data.已下发任务, name:'已下发任务'},
                                {value:data.就绪任务, name:'就绪任务'},
                                {value:data.进行中任务, name:'进行中任务'},
                                {value:data.完成任务, name:'完成任务'},
                                {value:data.撤销任务, name:'撤销任务'}
                            ],
                            itemStyle: {
                                emphasis: {
                                    shadowBlur: 10,
                                    shadowOffsetX: 0,
                                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                                }
                            }
                        }
                    ]
                };
                chart3.setOption(option3);  //执行该饼图并显示
            }
        });
    }
}
]);
/**
 * 用户登录
 */
bracketCtrls.controller('loginCtrl', [ '$scope', function($scope) {
    window.clearTimeout(time);
    $scope.login = function(loginInfo) {
        $("#submit").attr("disabled", true);
        $.ajax({
            type : "POST",
            url : BasePath + "/login.do",
            data : loginInfo,
            dataType : "json",
            success : function(data) {
                if(data.retCode == SUCCESS){
                    location.href = BasePath + "#/main";
                }else{
                    messageDanger("登录失败",data.retMessage);
                }
                $("#submit").removeAttr("disabled");
            },
            error : function(XMLHttpRequest, textStatus, errorThrown) {
                $("#submit").removeAttr("disabled");
                dangerAlert();
                console.log(errorThrown);
            }
        });
    };
} ]);
/**
 * 申请注册码
 */
bracketCtrls.controller('orderApply', [ '$scope', '$http', function($scope, $http) {
    if(checkRole('#/orderApply,','licenceManage')){
        return;
    }
    //省、市联动
    showLocation();
    $scope.save = function(applyInfo) {
        $("#submit").attr("disabled", true);
        applyInfo.province=$('#province').val();
        applyInfo.city=$('#city').val();
        $.ajax({
            type : "POST",
            url : BasePath + "/licenceno/insertOrder.do",
            data : applyInfo,
            dataType : "json",
            success : function(data) {
                if (data.retCode == SUCCESS) {
                    successAlert();
                    location.href = BasePath + "/#/orderInfo";
                } else {
                    messageDanger("申请注册码失败", data.retMessage);
                }
                $("#submit").removeAttr("disabled");
            }
        });
    };
    $scope.reset = function() {
        $scope.applyInfo = {};
        $('#province').val('');
        $('#city').val('');
        $('#loc_city').empty();
        $('#loc_city').append('<option value="">地级市</option>');
    };
} ]);
/**
 * 订单信息
 */
bracketCtrls.controller('orderInfo', [ '$scope', function($scope, $http) {
    if(checkRole('#/orderInfo,','licenceManage')){
        return;
    }
    var columns = [{
        field : 'orgname',
        title : '企业名称',
        align : 'center',
        valign : 'middle'
    }, {
        field : 'location',
        title : '地区',
        align : 'center',
        valign : 'middle'
    }, {
        field : 'contact',
        title : '联系人',
        align : 'center',
        valign : 'middle'
    }, {
        field : 'count',
        title : '订购数量',
        align : 'center',
        valign : 'middle'
    }];
    if(checkElement('licenceInfo,')){
        columns.push({
            title : '操作',
            align : 'center',
            valign : 'middle',
            formatter : operateFormatterForOrder,
            events : operateEventsForOrder
        });
    }
    $('#datatable').bootstrapTable({
        method : 'post',
        url : BasePath + '/licenceno/queryLicenceno.do',
        cache : false,
        striped : true,
        sidePagination : 'server',
        pagination : true,
        pageSize : 10,
        pageList : [ 10, 25, 50, 100, 200 ],
        showColumns : true,
        showRefresh : true,
        minimumCountColumns : 2,
        onLoadError: SessionTimeOut,
//		clickToSelect : true,
        columns : columns
    });
} ]);
/**
 * 订单下注册码信息
 */
bracketCtrls.controller('codeInfo', ['$scope', function($scope, $http) {
    if(checkRole('#/codeInfo,','licenceManage')){
        return;
    }
    var bussid = sessionStorage.getItem("bussid");
    var orgname = sessionStorage.getItem("orgname");
    if(bussid == null || bussid == "" || orgname == null || orgname == ""){
        location.href = BasePath + "/#/main";
        return;
    }
    $("#orgName").html('<font size="3px;"color="#1D2939">'+orgname+'</font> 企业下的注册码信息');
    $('#datatable').bootstrapTable({
        method : 'post',
        url : BasePath
        + '/licenceno/queryDetailForOrder.do?bussid='
        + bussid,
        cache : false,
        striped : true,
        sidePagination : 'server',
        pagination : true,
        pageSize : 10,
        pageList : [ 10, 25, 50, 100, 200 ],
        showColumns : true,
        showRefresh : true,
        minimumCountColumns : 2,
        onLoadError: SessionTimeOut,
        columns : [{
            field : 'licenceno',
            title : '注册码',
            align : 'center',
            valign : 'middle'
        }, {
            field : 'machinecode',
            title : '机器码',
            align : 'center',
            valign : 'middle'
        }, {
            field : 'expirytime',
            title : '有效期（月）',
            align : 'center',
            valign : 'middle'
        }, {
            field : 'activatortimeStr',
            title : '激活时间',
            align : 'center',
            valign : 'middle'
        }, {
            field : 'invalidationtimeStr',
            title : '失效时间',
            align : 'center',
            valign : 'middle'
        }, {
            field : 'state',
            title : '激活状态',
            align : 'center',
            valign : 'middle',
            formatter : operateFormatterForState
        } ]
    });
} ]);
/**
 * 用户信息
 */
bracketCtrls.controller('userInfo', [ '$scope', function($scope, $http) {
    if(checkRole('#/userInfo,','userManage')){
        return;
    }
    var columns = [ {
        field : 'username',
        title : '姓名',
        align : 'center',
        valign : 'middle'
    }, {
        field : 'loginname',
        title : '工号',
        align : 'center',
        valign : 'middle'
    }, {
        field : 'email',
        title : '邮箱',
        align : 'center',
        valign : 'middle'
    }, {
        field : 'mobilephone',
        title : '手机号',
        align : 'center',
        valign : 'middle'
    },{
        field : 'rolename',
        title : '角色',
        align : 'center',
        valign : 'middle'
    } ];
    if(sessionStorage.getItem("loginCompanyName") == ""){//该账号没有企业
        columns.push({
            field : 'companyname',
            title : '企业',
            align : 'center',
            valign : 'middle'
        });
    }
    if(checkElement('logoutUser,')){
        columns.push({
            title : '注销状态',
            align : 'center',
            valign : 'middle',
            formatter : operateFormatterForEditUser2
        });
        function updateState(id, state) {//更新用户状态
            $.ajax({
                type : "POST",
                url : BasePath + "/user/update4Userstate.do",
                data : {
                    'userid' : id,
                    'userstate' : state
                },
                dataType : "json",
                success : function(data) {
                    if (data.retCode == SUCCESS) {
                        successAlert();
                    } else {
                        messageDanger("更新用户状态失败", data.retMessage);
                        $('#datatable').bootstrapTable('refresh',{url : BasePath+ '/user/query.do'});
                    }
                }
            });
        }
    }
    if(checkElement('editUser,')){
        columns.push({
            title : '操作',
            align : 'center',
            valign : 'middle',
            formatter : operateFormatterForEditUser,
            events : operateEventsForUser
        });
    }
    if(checkElement('addUser,')){
        $('#addUser').attr("style","width: 110px;padding-bottom: 10px;display:block;");
    }
    $('#datatable').bootstrapTable({
        method : 'post',
        url : BasePath + '/user/query.do',
        cache : false,
        striped : true,
        sidePagination : 'server',
        pagination : true,
        pageSize : 10,
        pageList : [ 10, 25, 50, 100, 200 ],
        showColumns : true,
        showRefresh : true,
        minimumCountColumns : 2,
        onLoadSuccess : function() {
            for ( var i = 0; i < $('.toggle').length; i++) {
                $('.toggle').eq(i).toggles({
                    on : !$('.toggle').eq(i).hasClass('toggle-off')
                });
            }
            $('.toggle').on('toggle', function(e, active) {
                var id = $(this).attr('id');
                if (active) {
                    updateState(id, "1");
                } else {
                    updateState(id, "0");
                }
            });
        },
        onLoadError: SessionTimeOut,
        columns : columns
    });
    //模糊查询
    $('#button').click(function () {
        var name = encodeURIComponent($("#username").val());
        var loginname = encodeURIComponent($("#loginname").val());
        var email = encodeURIComponent($("#email").val());
        var mobilephone = encodeURIComponent($("#mobilephone").val());
        var userstate = encodeURIComponent($("#userstate").val());
        $('#datatable').bootstrapTable('refresh', {url: BasePath+'/user/query.do?username='+name+'&loginname='
            +loginname+'&email='+email+'&mobilephone='+mobilephone+'&userstate='+userstate});
    });

} ]);
/**
 * 用户重置密码
 */
bracketCtrls.controller('resetUserPassword', [ '$scope', function($scope, $http) {
    if(checkRole('#/resetUserPassword,','userManage')){
        return;
    }
    var columns = [ {
        field : 'username',
        title : '姓名',
        align : 'center',
        valign : 'middle'
    }, {
        field : 'loginname',
        title : '工号',
        align : 'center',
        valign : 'middle'
    }, {
        field : 'rolename',
        title : '角色',
        align : 'center',
        valign : 'middle'
    } ];
    if(sessionStorage.getItem("loginCompanyName") == ""){//该账号没有企业
        columns.push({
            field : 'companyname',
            title : '企业',
            align : 'center',
            valign : 'middle'
        });
    }
    columns.push({
        title : '操作',
        align : 'center',
        valign : 'middle',
        clickToSelect : false,
        formatter : operateFormatterForEditUser3,
        events : operateEventsForUser3
    });
    $('#datatable').bootstrapTable({
        method : 'post',
        url : BasePath + '/user/query.do',
        cache : false,
        striped : true,
        sidePagination : 'server',
        pagination : true,
        pageSize : 10,
        pageList : [ 10, 25, 50, 100, 200 ],
        showColumns : true,
        showRefresh : true,
        minimumCountColumns : 2,
        onLoadError: SessionTimeOut,
        columns : columns
    });
    $scope.resetPWD = function() {
        $.ajax({
            type : "POST",
            url : BasePath + "/user/resetUserPassword.do",
            data : {
                'userid' : sessionStorage.getItem("userid4ResetUserPWD"),
                'loginname':sessionStorage.getItem("loginname4ResetUserPWD")
            },
            dataType : "json",
            success : function(data) {
                if (data.retCode == SUCCESS) {
                    successAlert();
                } else {
                    messageDanger("重置用户密码失败", data.retMessage);
                }
            }
        });
    };
    //根据姓名模糊查询
    $('#button').click(function () {
        var name = encodeURIComponent($("#username").val());
        var loginname = encodeURIComponent($("#loginname").val());
        $('#datatable').bootstrapTable('refresh', {url: BasePath+'/user/query.do?username='+name+'&loginname='+loginname});
    });
} ]);
/**
 * 创建用户
 */
bracketCtrls.controller('creatUser', [ '$scope', '$http', function($scope, $http) {
    if(checkRole('#/creatUser,','userManage')){
        return;
    }
    if(sessionStorage.getItem("loginCompanyName") == ""){//该账号没有企业
        $('#role').attr("style","display:block;");
        $('#company').attr("style","display:block;");
        var output = [];
        $.ajax({    //查所有角色
            type : "POST",
            url : BasePath + "/role/selectRole.do",
            data : {},
            dataType : "json",
            success : function(data) {
                var list = data.rolelist;
                for ( var i = 0; i < list.length; i++) {
                    if(!(list[i].id == '1000000000000001' || list[i].id == '1000000000000002')){
                        output.push('<option value="' + list[i].id + '">' + list[i].name + '</option>');
                    }
                }
                $("#selectRole").html(output.join(''));
                $("#selectRole").select2({
                    width: '100%'
                });
                var output2 = [];
                $.ajax({    //查所有企业
                    type : "POST",
                    url : BasePath + "/company/queryList.do",
                    data : {},
                    dataType : "json",
                    success : function(data) {
                        if(data.retCode == SUCCESS){
                            var list2 = data.result;
                            for ( var i = 0; i < list2.length; i++) {
                                output2.push('<option value="' + list2[i].id + '">' + list2[i].name + '</option>');
                            }
                            $("#selectCompany").html(output2.join(''));
                            $("#selectCompany").select2({
                                width: '100%'
                            });
                            $("#onload").attr("style", "display:none;");
                            $("#panel-body").attr("style", "display:block;");
                        }else{
                            messageDanger("创建用户失败", data.retMessage);
                            location.href = BasePath + "/#/userInfo";
                        }
                    }
                });
            }
        });
    }else{
        $("#onload").attr("style", "display:none;");
        $("#panel-body").attr("style", "display:block;");
    }
    $scope.save = function(userInfo) {
        if(sessionStorage.getItem("loginCompanyName") == ""){//该账号没有企业
            var roleid = "";
            $("#selectRole option:selected").each(function() {
                roleid += $(this).attr("value");
            });
            userInfo.roleid = roleid;
            var companyid = "";
            $("#selectCompany option:selected").each(function() {
                companyid += $(this).attr("value");
            });
            userInfo.companyid = companyid;
        }
        $("#submit").attr("disabled", true);
        $.ajax({
            type : "POST",
            url : BasePath + "/user/add.do",
            data : userInfo,
            dataType : "json",
            success : function(data) {
                if (data.retCode == SUCCESS) {
                    successAlert();
                    location.href = BasePath + "/#/userInfo";
                } else {
                    messageDanger("创建用户失败", data.retMessage);
                }
                $("#submit").removeAttr("disabled");
            }
        });
    };
    $scope.reset = function() {
        $scope.userInfo = {};
    };
} ]);
/**
 * 用户修改信息
 */
bracketCtrls.controller('editUser', [ '$scope', '$http', function($scope, $http) {
    if(checkRole('#/editUser,','userManage')){
        return;
    }
    var userid = sessionStorage.getItem("userid4EditUser");
    var loginname = sessionStorage.getItem("loginname4EditUser");
    if(userid == null || userid == "" || loginname == null || loginname ==""){
        location.href = BasePath + "/#/main";
        return;
    }
    $("#userName").html('修改拨测人员  <font size="3px;"color="#1D2939">'+sessionStorage.getItem("username4EditUser")+'</font> 的信息');
    var username = sessionStorage.getItem("username4EditUser");
    var email = sessionStorage.getItem("email4EditUser");
    var mobilephone = sessionStorage.getItem("mobilephone4EditUser");
    var roleid = sessionStorage.getItem("roleid4EditUser"); //角色id
    var rolename = sessionStorage.getItem("rolename4EditUser"); //角色名称
    var companyid = sessionStorage.getItem("companyid4EditUser"); //企业id
    var companyname = sessionStorage.getItem("companyname4EditUser"); //企业名称
    //
    if(sessionStorage.getItem("loginCompanyName") == ""){//该账号没有企业
        $('#role').attr("style","display:block;");
        $('#company').attr("style","display:block;");
        var output = [];
        $.ajax({    //查所有角色
            type : "POST",
            url : BasePath + "/role/selectRole.do",
            data : {},
            dataType : "json",
            success : function(data) {
                var list = data.rolelist;
                for ( var i = 0; i < list.length; i++) {
                    if(!(list[i].id == '1000000000000001' || list[i].id == '1000000000000002')){
                        if(list[i].id == roleid){
                            output.push('<option selected="selected" value="' + list[i].id + '">' + list[i].name + '</option>');
                        }else{
                            output.push('<option value="' + list[i].id + '">' + list[i].name + '</option>');
                        }
                    }
                }
                $("#selectRole").html(output.join(''));
                $("#selectRole").select2({
                    width: '100%'
                });
                var output2 = [];
                $.ajax({    //查所有企业
                    type : "POST",
                    url : BasePath + "/company/queryList.do",
                    data : {},
                    dataType : "json",
                    success : function(data) {
                        if(data.retCode == SUCCESS){
                            var list2 = data.result;
                            for ( var i = 0; i < list2.length; i++) {
                                if(list2[i].id == companyid){
                                    output2.push('<option selected="selected" value="' + list2[i].id + '">' + list2[i].name + '</option>');
                                }else{
                                    output2.push('<option value="' + list2[i].id + '">' + list2[i].name + '</option>');
                                }
                            }
                            $("#selectCompany").html(output2.join(''));
                            $("#selectCompany").select2({
                                width: '100%'
                            });
                            $("#onload").attr("style", "display:none;");
                            $("#panel-body").attr("style", "display:block;");
                        }else{
                            messageDanger("修改用户失败", data.retMessage);
                            location.href = BasePath + "/#/userInfo";
                        }
                    }
                });
            }
        });
    }else{
        $("#onload").attr("style", "display:none;");
        $("#panel-body").attr("style", "display:block;");
    }
    //
    $scope.userInfo = {
        userid : userid,
        username : username,
        loginname : loginname,
        email : email,
        mobilephone : mobilephone,
//			roleid :roleid,  //角色id
    };
    $scope.save = function(userInfo) {
        if(sessionStorage.getItem("loginCompanyName") == ""){//该账号没有企业
            var roleid = "";
            $("#selectRole option:selected").each(function() {
                roleid += $(this).attr("value");
            });
            userInfo.roleid = roleid;
            var companyid = "";
            $("#selectCompany option:selected").each(function() {
                companyid += $(this).attr("value");
            });
            userInfo.companyid = companyid;
        }
        $("#submit").attr("disabled", true);
        $.ajax({
            type : "POST",
            url : BasePath + "/user/update.do",
            data : userInfo,
            dataType : "json",
            success : function(data) {
                if (data.retCode == SUCCESS) {
                    successAlert();
                    location.href = BasePath + "/#/userInfo";
                } else {
                    messageDanger("修改用户基本信息失败", data.retMessage);
                }
                $("#submit").removeAttr("disabled");
            }
        });
    };
    $scope.reset = function() {
        $scope.userInfo = {
            userid : userid,
            username : username,
            loginname : loginname,
            email : email,
            mobilephone : mobilephone,
        };
    };
} ]);
/**
 * 样本查看
 */
bracketCtrls.controller('sampleInfo', [ '$scope', function($scope, $http) {
    if(checkRole('#/sampleInfo,','sampleManage')){
        return;
    }
    $('#datepicker').datepicker(); //查询时间
    var columns = [{
        field : 'id',
        align : 'center',
        valign : 'middle; display: none'
    }, {
        field : 'name',
        title : '样本名',
        align : 'center',
        valign : 'middle'
    }, {
        field : 'md5',
        title : 'MD5',
        align : 'center',
        valign : 'middle'
    }, {
        field : 'type',
        title : '样本类型',
        align : 'center',
        valign : 'middle'
    },{
        field : 'type1',
        title : '样本种类',
        align : 'center',
        valign : 'middle'
    } ];
    if(sessionStorage.getItem("loginCompanyName") == ""){//该账号没有企业
        columns.push({
            field : 'companyname',
            title : '企业',
            align : 'center',
            valign : 'middle'
        });
    }
    columns.push({
        field : 'createtime',
        title : '创建时间',
        align : 'center',
        valign : 'middle'
    });
    $('#datatable').bootstrapTable({
        method : 'post',
        url : BasePath + '/sample/querySample.do',
        cache : false,
        striped : true,
        sidePagination : 'server',
        pagination : true,
        pageSize : 10,
        pageList : [ 10, 25, 50, 100, 200 ],
        showColumns : true,
        showRefresh : true,
        minimumCountColumns : 2,
        onLoadError: SessionTimeOut,
        columns : columns
    });
    //模糊查询
    $('#button').click(function () {
        var name = encodeURIComponent($("#name").val());
        var md5 = encodeURIComponent($("#md5").val());
        var type = encodeURIComponent($("#type").val());
        var type1 = encodeURIComponent($("#type1").val());
        var companyname = encodeURIComponent($("#companyname").val());
        var createtime1 = $("#datepicker").val(); //时间的值
        var createtime = encodeURIComponent(createtime1.replace(/[\\\/]/g,"-")); //转化为yyyy-mm-dd
        $('#datatable').bootstrapTable('refresh', {url: BasePath+'/sample/querySample.do?name='+name+'&md5='
            +md5+'&type='+type+'&createtime='+createtime+'&type1='+type1+'&companyname='+companyname});
    });
} ]);
/**
 * 测试样本信息
 */
bracketCtrls.controller('sampleTestInfo', [ '$scope', function($scope, $http) {
    if(checkRole('#/sampleTestInfo,','sampleManage')){
        return;
    }
    var state = 1;
    $('#datepicker').datepicker(); //查询时间
    var columns = [{
        checkbox : true
    }, {
        field : 'id',
        align : 'center',
        valign : 'middle; display: none'
    }, {
        field : 'name',
        title : '样本名',
        align : 'center',
        valign : 'middle'
    }, {
        field : 'md5',
        title : 'MD5',
        align : 'center',
        valign : 'middle'
    }, {
        field : 'type',
        title : '样本类型',
        align : 'center',
        valign : 'middle'
    },{
        field : 'type1',
        title : '样本种类',
        align : 'center',
        valign : 'middle'
    },{
        field : 'createtime',
        title : '创建时间',
        align : 'center',
        valign : 'middle'
    } ];
    if(checkElement('editSample,')){
        columns.push({
            title : '操作',
            align : 'center',
            valign : 'middle',
            formatter : operateFormatterForEditSampleName,
            events : operateEventsForSampleName
        });
    }
    $('#datatable').bootstrapTable({
        method : 'post',
        url : BasePath + '/sample/querySample.do?state='+state,
        cache : false,
        striped : true,
        sidePagination : 'server',
        pagination : true,
        pageSize : 10,
        pageList : [ 10, 25, 50, 100, 200 ],
        showColumns : true,
        showRefresh : true,
        minimumCountColumns : 2,
        onLoadError: SessionTimeOut,
        columns : columns
    });
    //模糊查询
    $('#button').click(function () {
        var name = encodeURIComponent($("#name").val());
        var md5 = encodeURIComponent($("#md5").val());
        var type = encodeURIComponent($("#type").val());
        var type1 = encodeURIComponent($("#type1").val());
        var createtime1 = $("#datepicker").val(); //时间的值
        var createtime = encodeURIComponent(createtime1.replace(/[\\\/]/g,"-")); //转化为yyyy-mm-dd
        $('#datatable').bootstrapTable('refresh', {url: BasePath+'/sample/querySample.do?name='+name+'&md5='
            +md5+'&type='+type+'&createtime='+createtime+'&type1='+type1+'&state='+state});
    });
    //删除样本
    if(checkElement('deleteSample,')){
        $('#deleteSample').attr("style","width: 106px;padding-bottom: 10px;display:block;");
        $scope.del = function() {
            var ids = "";
            for(var i=0;i<$("tr[class='selected']").length;i++){
                ids = ids + $("tr[class='selected']").eq(i).children('td').eq(1).html()+",";
            }
            if(ids == ""){
                return ;
            }
            $("#deleteBtn").attr("disabled", true);
            ids = ids.substring(0, ids.length-1);
            $.ajax({
                type : "POST",
                url : BasePath + "/sample/delete.do",
                data : {'ids':ids},
                dataType : "json",
                success : function(data) {
                    if (data.retCode == SUCCESS) {
                        successAlert();
                        $('#datatable').bootstrapTable('refresh', {url: BasePath+'/sample/querySample.do?state='+state});
                    } else if(data.retCode == "0050") {
                        messageDanger("删除样本失败", data.result);
                    } else {
                        messageDanger("删除样本失败", data.retMessage);
                    }
                    $("#deleteBtn").removeAttr("disabled");
                }
            });
        };
    }
    if(checkElement('uploadSample,')){
        $('#uploadSample').attr("style","width: 106px;padding-bottom: 10px;display:block;");
    }

} ]);
/**
 * 生产样本信息
 */
bracketCtrls.controller('sampleProduceInfo', [ '$scope', function($scope, $http) {
    if(checkRole('#/sampleProduceInfo,','sampleManage')){
        return;
    }
    var state = 0;
    $('#datepicker').datepicker(); //查询时间
    var columns = [
        {
            checkbox : true
        },
        {
            field : 'id',
            align : 'center',
            valign : 'middle; display: none'
        }, {
            field : 'name',
            title : '样本名',
            align : 'center',
            valign : 'middle'
        }, {
            field : 'md5',
            title : 'MD5',
            align : 'center',
            valign : 'middle'
        }, {
            field : 'type',
            title : '样本类型',
            align : 'center',
            valign : 'middle'
        },{
            field : 'type1',
            title : '样本种类',
            align : 'center',
            valign : 'middle'
        },
        {
            field : 'createtime',
            title : '创建时间',
            align : 'center',
            valign : 'middle'
        } ];
    if(checkElement('editSample,')){
        columns.push({
            title : '操作',
            align : 'center',
            valign : 'middle',
            formatter : operateFormatterForEditSampleName,
            events : operateEventsForSampleName
        });
    }
    $('#datatable').bootstrapTable({
        method : 'post',
        url : BasePath + '/sample/querySample.do?state='+state,
        cache : false,
        striped : true,
        sidePagination : 'server',
        pagination : true,
        pageSize : 10,
        pageList : [ 10, 25, 50, 100, 200 ],
        showColumns : true,
        showRefresh : true,
        minimumCountColumns : 2,
        onLoadError: SessionTimeOut,
        columns : columns
    });
    //模糊查询
    $('#button').click(function () {
        var name = encodeURIComponent($("#name").val());
        var md5 = encodeURIComponent($("#md5").val());
        var type = encodeURIComponent($("#type").val());
        var type1 = encodeURIComponent($("#type1").val());
        var createtime1 = $("#datepicker").val(); //时间的值
        var createtime = encodeURIComponent(createtime1.replace(/[\\\/]/g,"-")); //转化为yyyy-mm-dd
        $('#datatable').bootstrapTable('refresh', {url: BasePath+'/sample/querySample.do?name='+name+'&md5='
            +md5+'&type='+type+'&createtime='+createtime+'&type1='+type1+'&state='+state});
    });
    //删除样本
    if(checkElement('deleteSample,')){
        $('#deleteSample').attr("style","width: 106px;padding-bottom: 10px;display:block;");
        $scope.del = function() {
            var ids = "";
            for(var i=0;i<$("tr[class='selected']").length;i++){
                ids = ids + $("tr[class='selected']").eq(i).children('td').eq(1).html()+",";
            }
            if(ids == ""){
                return ;
            }
            $("#deleteBtn").attr("disabled", true);
            ids = ids.substring(0, ids.length-1);
            $.ajax({
                type : "POST",
                url : BasePath + "/sample/delete.do",
                data : {'ids':ids},
                dataType : "json",
                success : function(data) {
                    if (data.retCode == SUCCESS) {
                        successAlert();
                        $('#datatable').bootstrapTable('refresh', {url: BasePath+'/sample/querySample.do?state='+state});
                    } else if(data.retCode == "0050") {
                        messageDanger("删除样本失败", data.result);
                    } else {
                        messageDanger("删除样本失败", data.retMessage);
                    }
                    $("#deleteBtn").removeAttr("disabled");
                }
            });
        };
    }
    if(checkElement('uploadSample,')){
        $('#uploadSample').attr("style","width: 106px;padding-bottom: 10px;display:block;");
    }

} ]);
/**
 * 上传生产样本
 */
bracketCtrls.controller('uploadSample',['$scope', function($scope, $http) {
    if(checkRole('#/uploadSample,','sampleManage')){
        return;
    }
    $scope.save = function(sampleInfo) {
        if($("#file1").val()==""){
            messageDanger("上传生产样本失败", "未选择任何文件!");
            return;
        }
        sampleInfo.state = 0;
        $("#submit").attr("disabled", true);
        $.ajaxFileUpload({
            url : BasePath + "/sample/upload.do",
            data : sampleInfo,
            dataType : "json",
            secureuri: false, //是否需要安全协议，一般设置为false
            fileElementId: 'file1', //文件上传域的ID
            success : function(data) {
                if(data.retCode == SUCCESS){
                    successAlert();
                    location.href = BasePath + "/#/sampleProduceInfo";
                }else if (data.retCode == "0040"){
                    messageDanger("生产样本全部上传失败", data.result);
                }else if (data.retCode == "0050"){
                    messageSuccess("生产样本部分上传成功", data.result);
                    location.href = BasePath + "/#/sampleProduceInfo";
                }else{
                    messageDanger("上传生产样本失败", data.retMessage);
                }
                $("#submit").removeAttr("disabled");
            }
        });
    };
    $scope.reset = function() {
        $scope.sampleInfo = {};
    };
} ]);
/**
 * 上传测试样本
 */
bracketCtrls.controller('uploadSample1',['$scope', function($scope, $http) {
    if(checkRole('#/uploadSample1,','sampleManage')){
        return;
    }
    $scope.save = function(sampleInfo) {
        if($("#file1").val()==""){
            messageDanger("上传测试样本失败", "未选择任何文件!");
            return;
        }
        sampleInfo.state = 1;
        $("#submit").attr("disabled", true);
        $.ajaxFileUpload({
            url : BasePath + "/sample/upload.do",
            data : sampleInfo,
            dataType : "json",
            secureuri: false, //是否需要安全协议，一般设置为false
            fileElementId: 'file1', //文件上传域的ID
            success : function(data) {
                if(data.retCode == SUCCESS){
                    successAlert();
                    location.href = BasePath + "/#/sampleTestInfo";
                }else if (data.retCode == "0040"){
                    messageDanger("测试样本全部上传失败", data.result);
                }else if (data.retCode == "0050"){
                    messageSuccess("测试样本部分上传成功", data.result);
                    location.href = BasePath + "/#/sampleTestInfo";
                }else{
                    messageDanger("上传测试样本失败", data.retMessage);
                }
                $("#submit").removeAttr("disabled");
            }
        });
    };
    $scope.reset = function() {
        $scope.sampleInfo = {};
    };
} ]);
/**
 * 样本库信息
 */
bracketCtrls.controller('sampleBankInfo', [ '$scope', function($scope, $http) {
    if(checkRole('#/sampleBankInfo,','sampleBankManage')){
        return;
    }
    $('#datepicker').datepicker(); //查询时间
    var columns = [ {
        field : 'bankname',
        title : '样本库名',
        align : 'center',
        valign : 'middle'
    }, {
        field : 'type',
        title : '样本类型',
        align : 'center',
        valign : 'middle'
    } ];
    if(sessionStorage.getItem("loginCompanyName") == ""){//该账号没有企业
        columns.push({
            field : 'companyname',
            title : '企业',
            align : 'center',
            valign : 'middle'
        });
    }
    columns.push({
        field : 'createtime',
        title : '创建时间',
        align : 'center',
        valign : 'middle'
    });
    if(checkElement('manageSampleBySampleBank,')){
        columns.push({
            title : '操作',
            align : 'center',
            valign : 'middle',
            formatter : operateFormatterForSampleBank,
            events : operateEventsForSampleBank
        });
    }
    if(checkElement('addSampleBank,')){
        $('#addSampleBank').attr("style","width: 120px;padding-bottom: 10px;display:block;");
    }
    $('#datatable').bootstrapTable({
        method : 'post',
        url : BasePath + '/sampleBank/querySampleBank.do',
        cache : false,
        striped : true,
        sidePagination : 'server',
        pagination : true,
        pageSize : 10,
        pageList : [ 10, 25, 50, 100, 200 ],
        showColumns : true,
        showRefresh : true,
        minimumCountColumns : 2,
        onLoadError: SessionTimeOut,
        columns : columns
    });
    //根据样本库名模糊查询
    $('#button').click(function () {
        var bankname = encodeURIComponent($("#bankname").val());
        var type = encodeURIComponent($("#type").val());
        var createtime1 = $("#datepicker").val(); //时间的值
        var createtime = encodeURIComponent(createtime1.replace(/[\\\/]/g,"-")); //转化为yyyy-mm-dd
        $('#datatable').bootstrapTable('refresh', {url: BasePath+'/sampleBank/querySampleBank.do?bankname='+bankname+'&type='+type+'&createtime='+createtime});
    });

} ]);

/**
 * 创建URL任务
 */
bracketCtrls.controller('createHandle', [ '$scope', '$http', function($scope, $http) {
    if(checkRole('#/createHandle,','createManage')){
        return;
    }

    $scope.save = function(handleInfo) {
        $("#submit").attr("disabled", true);

        $.ajax({
            type : "POST",
            url : BasePath + "/handle/insertHandle.do",
            data : {
                "name": $('#name').val()
                , 'handleURL': $('#handleURL').val()
                , 'time': $('#time').val(),
                dataType: "json",
                success: function (data) {
                    if ( SUCCESS== SUCCESS) {
                        successAlert();
                        location.href = BasePath + "/#/handleInfo";
                    } else {
                        messageDanger("创建攻击端失败", data.retMessage);
                    }
                    $("#submit").removeAttr("disabled");
                }
            }
        });
    };
    $scope.reset = function() {
        $scope.handleInfo = {};
        $('#name').val('');
        $('#handleURL').val('');
        $('#time').val('');
    };
} ]);


/**
 * 处置URL信息
 */
bracketCtrls.controller('handleInfo', [ '$scope', function($scope, $http) {
    if(checkRole('#/handleInfo,','handleManage')){
        return;
    }
    var columns = [{
        field : 'name',
        title : '名称',
        align : 'center',
        valign : 'middle'
    }, {
        field : 'state',
        title : '状态',
        align : 'center',
        valign : 'middle',
        formatter : operateHandleForStates
    }, {
        field : 'disposal',
        title : '处置率(%)',
        align : 'center',
        valign : 'middle'
    }, {
        field : 'time',
        title : '次数',
        align : 'center',
        valign : 'middle'
    },{
        field : 'createtime',
        title : '创建时间',
        align : 'center',
        valign : 'middle'
    }];
    if(checkElement('editHandle,') || checkElement('configureHandle,') || checkElement('startHandleInfo,')){
        columns.push({
            title : '操作',
            align : 'center',
            valign : 'middle',
            formatter : operateFormatterForEditTargets,
            events : operateEventsForOrders
        });
    }
    if(checkElement('createHandleInfo,')){
        $('#createHandleInfo').attr("style","width: 110px;padding-bottom: 10px;display:block;");
    }


    $('#datatable').bootstrapTable({
        method : 'post',
        url : BasePath + '/handle/queryHandle.do',
        cache : false,
        striped : true,
        sidePagination : 'server',
        pagination : true,
        pageSize : 5,
        pageList : [ 5,10, 25, 50, 100, 200 ],
        showColumns : true,
        showRefresh : true,
        minimumCountColumns : 2,
        onLoadSuccess : function() {
            for ( var i = 0; i < $('.toggle').length; i++) {
                $('.toggle').eq(i).toggles({
                    on : !$('.toggle').eq(i).hasClass('toggle-off')
                });
            }
            $('.toggle').on('toggle', function(e, active) {
                var id = $(this).attr('id');
                $(this).attr("disabled", true);
                if (active) {
                    if ($(this).hasClass('ftp')) {
                        updateFtp(id, "0");
                    }else {
                        updateState(id, "0");
                    }
                } else {
                    if ($(this).hasClass('ftp')) {
                        updateFtp(id, "1");
                    }else {
                        updateState(id, "1");
                    }
                }
            });
            nowState("/target/getHeartbeat.do");
        },
        onLoadError: SessionTimeOut,
        columns : columns
    });
} ]);

/**
 * URL连接信息
 */
bracketCtrls.controller('seeHandle', ['$scope', function($scope, $http) {
    if(checkRole('#/seeHandle,','seeHandleManage')){
        return;
    }
    var id = sessionStorage.getItem("id");
    if(id == null || id == ""){
        location.href = BasePath + "/#/main";
        return;
    }
    $('#datatable').bootstrapTable({
        method : 'post',
        url : BasePath
        + '/handle/queryHandleSee.do?id='
        + id,
        cache : false,
        striped : true,
        sidePagination : 'server',
        pagination : true,
        pageSize : 10,
        pageList : [ 10, 25, 50, 100, 200 ],
        showColumns : true,
        showRefresh : true,
        minimumCountColumns : 2,
        onLoadError: SessionTimeOut,
        columns : [{
            field : 'URL',
            title : 'URL',
            align : 'center',
            valign : 'middle'
        },{
            field : 'state',
            title : '处置状态',
            align : 'center',
            valign : 'middle',
            formatter : operateFormatterForStates
        } ]
    });
} ]);




bracketCtrls.controller('countHandle', ['$scope', function($scope, $http) {
    if(checkRole('#/countHandle,','countHandleManage')){
        return;
    }
    var id = sessionStorage.getItem("id");
    if(id == null || id == ""){
        location.href = BasePath + "/#/main";
        return;
    }

} ]);





/**
 * 靶机信息
 */
bracketCtrls.controller('targetInfo', [ '$scope', function($scope, $http) {
    if(checkRole('#/targetInfo,','targetManage')){
        return;
    }
    var columns = [ {
        title : '实时状态',
        align : 'center',
        valign : 'middle',
        formatter : operateFormatterForEditTarget4
    }, {
        field : 'location',
        title : '地区',
        align : 'center',
        valign : 'middle'
    }, {
        field : 'operator',
        title : '运营商',
        align : 'center',
        valign : 'middle'
    }, {
        field : 'ip',
        title : 'IP地址',
        align : 'center',
        valign : 'middle'
    }, {
        field : 'targetport',
        title : '端口',
        align : 'center',
        valign : 'middle'
    }, {
        field : 'user',
        title : '用户',
        align : 'center',
        valign : 'middle'
    }, {
        field : 'arrangestate',
        title : '部署状态',
        align : 'center',
        valign : 'middle'
    } ];
    if(checkElement('serviceType,')){
        columns.push({
            title : '服务状态',
            align : 'center',
            valign : 'middle',
            formatter : operateFormatterForEditTarget2,
            events : operateFormatterForEditTarget2Event
        });
    }
    if(checkElement('logoutTarget,')){
        columns.push({
            title : '启用/禁用',
            align : 'center',
            valign : 'middle',
            formatter : operateFormatterForEditTarget3
        });
        function updateState(id, state) {
            $.ajax({
                type : "POST",
                url : BasePath + "/target/update4State.do",
                data : {
                    'id' : id,
                    'state' : state
                },
                dataType : "json",
                success : function(data) {
                    if (data.retCode == SUCCESS) {
                        successAlert();
                    } else {
                        messageDanger("更新靶机状态失败", data.retMessage);
                    }
                    $('#datatable').bootstrapTable('refresh',{url : BasePath+ '/target/queryTarget.do'});
                }
            });
        }
    }
    if(checkElement('editTarget,') || checkElement('configureTarget,') || checkElement('arrangeTarget,') || checkElement('uninstallTarget,')){
        columns.push({
            title : '操作',
            align : 'center',
            valign : 'middle',
            formatter : operateFormatterForEditTarget,
            events : operateEventsForTarget
        });
    }
    if(checkElement('addTarget,')){
        $('#addTarget').attr("style","width: 110px;padding-bottom: 10px;display:block;");
    }
    $('#datatable').bootstrapTable({
        method : 'post',
        url : BasePath + '/target/queryTarget.do',
        cache : false,
        striped : true,
        sidePagination : 'server',
        pagination : true,
        pageSize : 5,
        pageList : [ 5,10, 25, 50, 100, 200 ],
        showColumns : true,
        showRefresh : true,
        minimumCountColumns : 2,
        onLoadSuccess : function() {
            for ( var i = 0; i < $('.toggle').length; i++) {
                $('.toggle').eq(i).toggles({
                    on : !$('.toggle').eq(i).hasClass('toggle-off')
                });
            }
            $('.toggle').on('toggle', function(e, active) {
                var id = $(this).attr('id');
                $(this).attr("disabled", true);
                if (active) {
                    if ($(this).hasClass('ftp')) {
                        updateFtp(id, "0");
                    }else {
                        updateState(id, "0");
                    }
                } else {
                    if ($(this).hasClass('ftp')) {
                        updateFtp(id, "1");
                    }else {
                        updateState(id, "1");
                    }
                }
            });
            nowState("/target/getHeartbeat.do");
        },
        onLoadError: SessionTimeOut,
        columns : columns
    });
    $scope.downtime = function() {
        var id = sessionStorage.getItem('id4DowntimeTarget');
        $.ajax({
            type : "POST",
            url : BasePath + "/target/downtime.do",
            data : {'id':id},
            dataType : "json",
            success : function(data) {
                if (data.retCode == SUCCESS) {
                    successAlert();
                    $('#datatable').bootstrapTable('refresh',{url : BasePath+ '/target/queryTarget.do'});
                } else{
                    messageDanger("靶机宕机失败", data.retMessage);
                }
            }
        });
    }
} ]);
/**
 * 创建靶机
 */
bracketCtrls.controller('creatTarget', [ '$scope', '$http', function($scope, $http) {
    if(checkRole('#/creatTarget,','targetManage')){
        return;
    }
    //省、市联动
    showLocation();
    $scope.save = function(targetInfo) {
        $("#submit").attr("disabled", true);
        var city = $("#city").val();
        var province = $("#province").val();
        $.ajax({
            type : "POST",
            url : BasePath + "/target/add.do",
            data : {'city':city,'province':province,'ip':targetInfo.ip,'operator':targetInfo.operator,
                'user':targetInfo.user,'password':targetInfo.password,'targetport':targetInfo.targetport},
            dataType : "json",
            success : function(data) {
                if (data.retCode == SUCCESS) {
                    successAlert();
                    location.href = BasePath + "/#/targetInfo";
                } else{
                    messageDanger("创建靶机失败", data.retMessage);
                }
                $("#submit").removeAttr("disabled");
            }
        });
    };
    $scope.reset = function() {
        $scope.targetInfo = {};
        $('#city').val('');
        $('#loc_city').empty();
        $('#loc_city').append('<option value="">地级市</option>');
    };
} ]);
/**
 * 修改靶机基本信息
 */
bracketCtrls.controller('editTarget', [ '$scope', '$http', function($scope, $http) {
    if(checkRole('#/editTarget,','targetManage')){
        return;
    }
    var id = sessionStorage.getItem("id4EditTarget");
    var user = sessionStorage.getItem("user4EditTarget");
    if(id == null || id == "" || user == null || user == ""){
        location.href = BasePath + "/#/main";
        return;
    }
    $("#targetName").html('修改IP及端口为  <font size="3px;"color="#1D2939">'+sessionStorage.getItem("ip4EditTarget")+' : '+sessionStorage.getItem("targetport4EditTarget")+'</font> 的靶机信息');
    //省、市联动
    showLocation();
    var location1 = sessionStorage.getItem("location4EditTarget");
    var operator = sessionStorage.getItem("operator4EditTarget");
    var ip = sessionStorage.getItem("ip4EditTarget");
    var password = sessionStorage.getItem("password4EditTarget");
    var targetport = parseInt(sessionStorage.getItem("targetport4EditTarget"));
    var arrangestate = sessionStorage.getItem("arrangestate4EditTarget");
    var province="",city="";
    if(location1.indexOf(" - ")>0){
        province = location1.substring(0,location1.indexOf(" "));
        city = location1.substring(location1.indexOf("-")+2,location1.length);
    }else{
        province = location1;
    }
    $scope.targetInfo = {
        id : id,
        ip : ip,
        password : password,
        user : user,
        targetport : targetport,
        arrangestate : arrangestate,
    };
    $('#oldProvince').html(province);
    if(city==""){
        $('#oldCity').html("-无-");
    }else{
        $('#oldCity').html(city);
    }
    $('#oldOperator').html(operator);
    if(operator=="中国移动"){
        operator = '0';
    }else if(operator=="中国联通"){
        operator = '1';
    }else{
        operator = '2';
    }
    $('#city').val(city);
    $('#province').val(province);
    $scope.save = function(targetInfo) {
        $("#submit").attr("disabled", true);
        if($('#province').val()!=null && $('#province').val()!=""){
            province = $('#province').val();
            city = $('#city').val();
        }
        if($('#operator').val()!=""){
            operator = $('#operator').val();
        }
        targetInfo.province = province;
        targetInfo.city = city;
        targetInfo.operator = operator;
        $.ajax({
            type : "POST",
            url : BasePath + "/target/update.do",
            data : targetInfo,
            dataType : "json",
            success : function(data) {
                if (data.retCode == SUCCESS) {
                    successAlert();
                    location.href = BasePath + "/#/targetInfo";
                } else {
                    messageDanger("修改靶机基本信息失败", data.retMessage);
                }
                $("#submit").removeAttr("disabled");
            }
        });
    };
    $scope.reset = function() {
        $scope.targetInfo = {
            id : id,
            ip : ip,
            password : password,
            user : user,
            targetport : targetport,
            arrangestate : arrangestate,
        };
        $('#province').val(province);
        $('#loc_province').val("");
        $('#city').val(city);
        $('#loc_city').empty();
        $('#loc_city').append('<option value="">地级市</option>');
        $('#operator').val("");
    };
} ]);

/**
 * 修改配置信息
 */
bracketCtrls.controller('configureTarget', [ '$scope', '$http', function($scope, $http) {
    if(checkRole('#/configureTarget,','configureTarget')){
        return;
    }
    var id = sessionStorage.getItem("id4ConfigureTarget");
    var user = sessionStorage.getItem("user4ConfigureTarget");
    if(id == null || id == "" ){
        location.href = BasePath + "/#/main";
        return;
    }
    $("#targetName").html('修改IP及端口为  <font size="3px;"color="#1D2939">'+sessionStorage.getItem("ip4ConfigureTarget")+' : '+sessionStorage.getItem("targetport4ConfigureTarget")+'</font> 的靶机信息');
    var httpport = sessionStorage.getItem("httpport4ConfigureTarget");
    var ftpport = sessionStorage.getItem("ftpport4ConfigureTarget");
    var popport = sessionStorage.getItem("popport4ConfigureTarget");
    var smtpport = sessionStorage.getItem("smtpport4ConfigureTarget");
    var mailuser = sessionStorage.getItem("mailuser4ConfigureTarget");
    var domainname = sessionStorage.getItem("domainname4ConfigureTarget");
    $scope.targetInfo = {
        id : id,
        httpport : httpport,
        ftpport : ftpport,
        popport : popport,
        smtpport : smtpport,
        mailuser : mailuser,
        domainname : domainname,
    };
    $scope.save = function(targetInfo) {
        $.ajax({
            type: "POST",
            url: BasePath + "/target/updateConfigure.do",
            data: targetInfo,
            dataType: "json",
            success: function (data) {
                if (data.retCode == SUCCESS) {
                    successAlert();
                    location.href = BasePath + "/#/targetInfo";
                } else {
                    messageDanger("配置靶机基本信息失败", data.retMessage);
                }
                $("#submit").removeAttr("disabled");
            }
        });
    };
} ]);







/**
 * 修改样本基本信息
 */
bracketCtrls.controller('editSample', [ '$scope', '$http', function($scope, $http) {
    if(checkRole('#/editSample,','sampleManage')){
        return;
    }
    var updateFlag = sessionStorage.getItem("updateFlag"); //标识不同的样本
    if(updateFlag == 0){
        $("#backInfo").html('<a href="#/sampleProduceInfo" class="btn btn-danger">返回</a>');
        $("#sampleFlag").html('<a href="#/sampleProduceInfo">生产样本信息</a>');
        $("#updatesample").html('修改生产样本');
        $("#updateSampleName").html('修改生产样本名');
    }
    if(updateFlag == 1){
        $("#backInfo").html('<a href="#/sampleTestInfo" class="btn btn-danger">返回</a>');
        $("#sampleFlag").html('<a href="#/sampleTestInfo">测试样本信息</a>');
        $("#updatesample").html('修改测试样本');
        $("#updateSampleName").html('修改测试样本名');
    }
    //
    var id = sessionStorage.getItem("id4EditSample");
    if(id == null || id ==""){
        location.href=  BasePath + "/#/main";
        return;
    }
    var name = sessionStorage.getItem("name4EditSample");
    $("#sampleName").html('修改样本名为  <font size="3px;"color="#1D2939">'+name+'</font> 的样本信息');
    $scope.sampleInfo = {
        id : id,
        name : name,
    };
    $scope.save = function(sampleInfo) {
        $("#submit").attr("disabled", true);
        $.ajax({
            type : "POST",
            url : BasePath + "/sample/update.do",
            data : sampleInfo,
            dataType : "json",
            success : function(data) {
                if (data.retCode == SUCCESS) {
                    successAlert();
                    if(updateFlag == 0){
                        location.href = BasePath + "/#/sampleProduceInfo";
                    }
                    if(updateFlag == 1){
                        location.href = BasePath + "/#/sampleTestInfo";
                    }
                    sessionStorage.setItem("updateFlag","");
                } else {
                    messageDanger("修改样本基本信息失败", data.retMessage);
                }
                $("#submit").removeAttr("disabled");
            }
        });
    };
    $scope.reset = function() {
        $scope.sampleInfo = {
            id : id,
            name : name,
        };
    };
    sessionStorage.setItem("updateFlag","");
} ]);
/**
 * 创建样本库
 */
bracketCtrls.controller('creatSampleBank', [ '$scope', '$http', function($scope, $http) {
    if(checkRole('#/creatSampleBank,','sampleBankManage')){
        return;
    }
    $scope.save = function(sampleBankInfo) {
        sessionStorage.setItem("type4CreatSampleBank", sampleBankInfo.type);
        sessionStorage.setItem("bankname4CreatSampleBank", sampleBankInfo.bankname);
        $.ajax({
            type : "POST",
            url : BasePath + "/sampleBank/checkSampleBankName.do",
            data : sampleBankInfo,
            dataType : "json",
            success : function(data) {
                if (data.retCode == SUCCESS) {
                    if(sampleBankInfo.selectMethod == "0"){
                        location.href = BasePath + "/#/select2Sample";
                    }else{  //随机选取样本
                        location.href = BasePath + "/#/selectrandom2Sample";
                    }
                } else {
                    messageDanger("检查名称唯一性失败!", data.retMessage);
                }
            }
        });
    };
    $scope.reset = function() {
        $scope.sampleBankInfo = {};
    };
} ]);
/**
 * 手动选取样本
 */
bracketCtrls.controller('select2Sample', ['$scope','$http', function($scope, $http) {
    if(checkRole('#/select2Sample,','sampleBankManage')){
        return;
    }
    var type = sessionStorage.getItem("type4CreatSampleBank");
    var bankname = sessionStorage.getItem("bankname4CreatSampleBank");
    if(type == null || type =="" || bankname == null || bankname == ""){
        location.href = BasePath + "/#/main";
        return;
    }
    var output = [];
    $.ajax({
        type : "POST",
        url : BasePath + "/sample/querySampleByType.do",
        data : {
            'type' : type,
        },
        dataType : "json",
        success : function(data) {
            if (data.retCode == SUCCESS) {
                var list = data.result;
                for ( var i = 0; i < list.length; i++) {
                    var type;
                    if(list[i].type1==0){
                        type = "恶意样本";
                    }
                    if(list[i].type1==1){
                        type = "正常样本";
                    }
                    if(list[i].type1==2){
                        type = "疑似样本";
                    }
                    output.push('<option value="' + list[i].id + '">'
                        + list[i].name +" -- "+type+'</option>');
                }
                $(".select2").html(output.join(''));
                $(".select2").select2();
                $(".select2").width("100%");
                $("#onload").attr("style", "display:none;");
                $("#panel-body").attr("style", "display:block;");
            } else {
                messageDanger("样本列表暂无数据", data.retMessage);
                location.href = BasePath + "/#/creatSampleBank";
            }
        }
    });
    $scope.save = function() {
        $("#submit").attr("disabled", true);
        var ids = "";
        $(".select2 option:selected").each(function() {
            ids += $(this).attr("value") + ",";
        });
        ids = ids.substring(0, ids.length - 1);
        $.ajax({
            type : "POST",
            url : BasePath + "/sampleBank/addSampleBank.do",
            data : {
                'bankname' : bankname,
                'ids' : ids,
                'type' : type,
            },
            dataType : "json",
            success : function(data) {
                if (data.retCode == SUCCESS) {
                    successAlert();
                    location.href = BasePath + "/#/sampleBankInfo";
                } else if(data.retCode == "1502"){
                    messageSuccess("创建样本库成功", data.retMessage);
                } else {
                    messageDanger("创建样本库失败", data.retMessage);
                    location.href = BasePath + "/#/creatSampleBank";
                }
                $("#submit").removeAttr("disabled");
            }
        });
    };
} ]);
/**
 * 随机选取样本
 */
bracketCtrls.controller('selectrandom2Sample', ['$scope','$http', function($scope, $http) {
    if(checkRole('#/selectrandom2Sample,','sampleBankManage')){
        return;
    }
    var type = sessionStorage.getItem("type4CreatSampleBank");
    var bankname = sessionStorage.getItem("bankname4CreatSampleBank");
    if(type == null || type =="" || bankname == null || bankname == ""){
        location.href = BasePath + "/#/main";
        return;
    }
    var count;
    var nomalSampleCount;
    var likeSampleCount;
    var evilSampleCount;
    $.ajax({
        type : "POST",
        url : BasePath + "/sample/addSampleBankRandomMax.do",
        data :{
            'type' : type,  //样本类型
        },
        dataType : "json",
        success : function(data) {
            if (data.retCode == SUCCESS) {
                var map = data.result; //不同样本类型的样本数量
                var typeStr;
                if(type=="cmcc"){
                    typeStr = "移动互联网疑似病毒样本";
                }
                if(type=="virus"){
                    typeStr = "木马和僵尸网络病毒样本";
                }
                count = Number(map.sampleTotalCount); //总的数量
                evilSampleCount = Number(map.evilSampleCount); //恶意
                nomalSampleCount = Number(map.nomalSampleCount); //正常
                likeSampleCount = Number(map.likeSampleCount);   //疑似
                $("#msg").html("* 抽取数量至少为0，"+typeStr+"("+count+"个)"+"下的恶意样本总数为"+evilSampleCount+"个");
                $("#msg1").html("可以不填默认为0，"+typeStr+"("+count+"个)"+"下的正常样本总数为"+nomalSampleCount+"个");
                $("#msg2").html("可以不填默认为0，"+typeStr+"("+count+"个)"+"下的疑似样本总数为"+likeSampleCount+"个");
                $("#onload").attr("style", "display:none;");
                $("#panel-body").attr("style", "display:block;");
            } else {
                messageDanger("暂无样本数据", data.retMessage);
                location.href = BasePath + "/#/creatSampleBank";
            }
        }
    });
    $scope.save = function(sampleBankInfo) {
        var numb = Number(sampleBankInfo.numb);  //恶意样本数量
        var nomalNum = Number($("#nomalSampleNum").val()); //取得输入框里的正常样本值
        var likeNum = Number($("#likeSampleNum").val());   //取得输入框里的疑似样本值
        if(nomalNum==""||nomalNum==null){
            nomalNum = 0;
        }
        if(likeNum==""||likeNum==null){
            likeNum = 0;
        }
        if(nomalNum > nomalSampleCount){
            nomalNum = nomalSampleCount;
        }
        if(likeNum > likeSampleCount){
            likeNum = likeSampleCount;
        }
        if(numb > evilSampleCount){
            numb = count;
        }
        $("#submit").attr("disabled", true);
        $.ajax({
            type : "POST",
            url : BasePath + "/sampleBank/addSampleBankRandom.do",
            data : {
                'bankname' : bankname,
                'type' : type,
                'numb' : numb,
                'nomalNum': nomalNum,
                'likeNum': likeNum
            },
            dataType : "json",
            success : function(data) {
                if (data.retCode == SUCCESS) {
                    successAlert();
                    location.href = BasePath + "/#/sampleBankInfo";
                } else if(data.retCode == "1502"){
                    messageSuccess("创建样本库成功", data.retMessage);
                } else {
                    messageDanger("创建样本库失败", data.retMessage);
                    location.href = BasePath + "/#/creatSampleBank";
                }
                $("#submit").removeAttr("disabled");
            }
        });
    };
} ]);
/**
 * 样本库下样本信息
 */
bracketCtrls.controller('relationInfo',['$scope', function($scope, $http) {
    if(checkRole('#/relationInfo,','sampleBankManage')){
        return;
    }
    var bankid = sessionStorage.getItem("bankid4AddSample");
    if(bankid == null || bankid == ""){
        location.href = BasePath + "/#/main";
        return;
    }
    $("#samplebankName").html('<font size="3px;"color="#1D2939">'+sessionStorage.getItem("bankname4Sample")+'</font> 样本库下的样本信息');
    var flag = sessionStorage.getItem("flag");
    var columns = [{
        field : 'smplename',
        title : '样本名',
        align : 'center',
        valign : 'middle'
    },{
        field : 'md5',
        title : 'MD5',
        align : 'center',
        valign : 'middle'
    },{
        field : 'type',
        title : '样本类型',
        align : 'center',
        valign : 'middle'
    },{
        field : 'type1',
        title : '样本种类',
        align : 'center',
        valign : 'middle'
    }];
    if(checkElement('deleteSampleBySampleBank,') && flag == 1){
        columns.push({
            title : '操作',
            align : 'center',
            valign : 'middle',
            formatter : operateFormatterForRelation,
            events : operateEventsForRelation
        });
        $scope.del = function() {
            $.ajax({
                type : "POST",
                url : BasePath+ "/sampleRelation/delete.do",
                data : {
                    'sampleid' : sessionStorage.getItem("sampleid4DeleteSample"),
                    'bankid' : bankid
                },
                dataType : "json",
                success : function(data) {
                    if (data.retCode == SUCCESS) {
                        successAlert();
                        $('#datatable').bootstrapTable('refresh',{url : BasePath+ '/sampleRelation/query.do?bankid='+ bankid});
                    } else {
                        messageDanger("删除样本失败", data.retMessage);
                    }
                }
            });
        };
    }
    if(checkElement('addSampleBySampleBank,') && flag == 1){
        $('#addSampleBySampleBank').attr("style","width: 110px;padding-bottom: 10px;display:block;");
    }
    if(flag == 0 && (checkElement('deleteSampleBySampleBank,') || checkElement('addSampleBySampleBank,'))){
        $("#tiShi").show();
    }
    $('#datatable').bootstrapTable({
        method : 'post',
        url : BasePath+ '/sampleRelation/query.do?bankid='+ bankid,
        cache : false,
        striped : true,
        sidePagination : 'server',
        pagination : true,
        pageSize : 10,
        pageList : [ 10, 25, 50, 100,200 ],
        showColumns : true,
        showRefresh : true,
        minimumCountColumns : 2,
        onLoadError: SessionTimeOut,
        columns : columns
    });
} ]);
/**
 * 样本库添加样本
 */
bracketCtrls.controller('creatRelation', ['$scope','$http', function($scope, $http) {
    if(checkRole('#/creatRelation,','sampleBankManage')){
        return;
    }
    var type = sessionStorage.getItem("type4AddSample");
    var bankid = sessionStorage.getItem("bankid4AddSample");
    if(bankid == null || bankid == "" || type == null || type == ""){
        location.href = BasePath + "/#/main";
        return;
    }
    $("#samplebankName").html('<font size="3px;"color="#1D2939">'+sessionStorage.getItem("bankname4Sample")+'</font> 样本库下添加样本');
    if (type == "木马和僵尸网络病毒样本") {
        type = 'virus';
    }else if(type == "移动互联网疑似病毒样本"){
        type = 'cmcc';
    }
    var output = [];
    $.ajax({
        type : "POST",
        url : BasePath + "/sample/querySampleByType.do",
        data : {
            'type' : type,
            'isOpen' : 'y',
            'bankid' : bankid,
        },
        dataType : "json",
        success : function(data) {
            if (data.retCode == SUCCESS) {
                var list = data.result;
                for ( var i = 0; i < list.length; i++) {
                    var type;
                    if(list[i].type1==0){
                        type = "恶意样本";
                    }
                    if(list[i].type1==1){
                        type = "正常样本";
                    }
                    if(list[i].type1==2){
                        type = "疑似样本";
                    }
                    output.push('<option value="' + list[i].id + '">'
                        + list[i].name+" -- "+type+'</option>');
                }
                $(".select2").html(output.join(''));
                $(".select2").select2();
                $(".select2").width("100%");
                $("#onload").attr("style", "display:none;");
                $("#panel-body").attr("style", "display:block;");
            } else{
                messageDanger("样本列表暂无数据", data.retMessage);
                location.href = BasePath + "/#/relationInfo";
            }
        }
    });
    $scope.save = function() {
        $("#submit").attr("disabled", true);
        var ids = "";
        $(".select2 option:selected").each(function() {
            ids += $(this).attr("value") + ",";
        });
        ids = ids.substring(0, ids.length - 1);
        if(ids == ""){
            messageDanger("添加样本失败", "未选择样本!");
            $("#submit").removeAttr("disabled");
            return;
        }
        $.ajax({
            type : "POST",
            url : BasePath + "/sampleRelation/add.do",
            data : {
                'ids' : ids,
                'bankid' : bankid,},
            dataType : "json",
            success : function(data) {
                if (data.retCode == SUCCESS) {
                    successAlert();
                    location.href = BasePath+ "/#/relationInfo";
                } else{
                    messageDanger("添加样本失败", data.retMessage);
                }
                $("#submit").removeAttr("disabled");
            }
        });
    };
} ]);
/**
 * 任务信息
 */
bracketCtrls.controller('taskInfo', [ '$scope', function($scope, $http) {
    if(checkRole('#/taskInfo,','taskManage')){
        return;
    }
    //省、市联动
    showLocation();
    var columns = [ {
        field : 'name',
        title : '任务名称',
        align : 'center',
        valign : 'middle'
    }, {
        field : 'location',
        title : '拨测地区',
        align : 'center',
        valign : 'middle'
    }, {
        field : 'operator',
        title : '运营商',
        align : 'center',
        valign : 'middle'
    }, {
        field : 'executor',
        title : '执行人员',
        align : 'center',
        valign : 'middle'
    }  ];
    if(sessionStorage.getItem("loginCompanyName") == ""){//该账号没有企业
        columns.push({
            field : 'companyname',
            title : '企业',
            align : 'center',
            valign : 'middle'
        });
    }
    columns.push({
        title : '任务进度',
        align : 'center',
        valign : 'middle; width:440px',
        formatter : operateFormatterForTasktype,  //任务进度条用
    });
    if(checkElement('taskCancel,') || checkElement('taskMore,') || checkElement('giveTask,') || checkElement('okTask,')){
        columns.push({
            title : '操作',
            align : 'center',
            valign : 'middle',
            formatter : operateFormatterForTask,
            events : operateEventsForTask
        });
    }
    if(checkElement('taskCancel,')){
        $scope.back = function(){
            $.ajax({
                type : "POST",
                url : BasePath + "/task/backTask.do",
                data : {'taskid' : sessionStorage.getItem("taskid4BackTask")},
                dataType : "json",
                success : function(data) {
                    if (data.retCode == SUCCESS) {
                        successAlert();
                        $('#datatable').bootstrapTable('refresh',{url : BasePath+ '/task/queryTask.do'});
                    } else{
                        messageDanger("撤销任务失败", data.retMessage);
                    }
                }
            });
        };
    }
    if(checkElement('addTask,')){
        $('#addTask').attr("style","width: 110px;padding-bottom: 10px;display:block;");
    }
    $('#datatable').bootstrapTable({
        method : 'post',
        url : BasePath + '/task/queryTask.do',
        cache : false,
        striped : true,
        sidePagination : 'server',
        pagination : true,
        pageSize : 10,
        pageList : [ 10, 25, 50, 100, 200 ],
        showColumns : true,
        showRefresh : true,
        minimumCountColumns : 2,
        onLoadSuccess : function() {
            for ( var i = 0; i < $('.toggle').length; i++) {
                $('.toggle').eq(i).toggles({
                    on : !$('.toggle').eq(i).hasClass('toggle-off')
                });
            }
            $('.toggle').on('toggle', function(e, active) {
                var id = $(this).attr('id');
                $(this).attr("disabled", true);
                if (active) {
                    updateHpstate(id, "0");
                } else {
                    updateHpstate(id, "1");
                }
            });
        },
        onLoadError: SessionTimeOut,
        columns : columns
    });
    //模糊查询
    $('#button').click(function () {
        var taskname = encodeURIComponent($("#taskname").val());
        var province = encodeURIComponent($("#province").val());
        var city = encodeURIComponent($("#city").val());
        var operator = encodeURIComponent($("#operator").val());
        var executor = encodeURIComponent($("#executor").val());
        var type = encodeURIComponent($("#type").val());
        $('#datatable').bootstrapTable('refresh',
            {url: BasePath+'/task/queryTask.do?taskname='+taskname+'&province='+province+'&city='+city+'&operator='+operator+'&username='+executor+'&tasktype='+type});
    });
} ]);
/**
 * 创建任务
 */
bracketCtrls.controller('creatTask', ['$scope','$http', function($scope, $http) {
    if(checkRole('#/creatTask,','taskManage')){
        return;
    }
    //查询该企业的任务数量是否超过出
    $.ajax({
        type : "POST",
        url : BasePath + "/task/getTaskNumber.do",
        data: {},
        dataType : "json",
        success : function(data) {
            if (data.retCode == SUCCESS) {
            }else{
                messageDanger("创建任务失败", data.retMessage);
                location.href = BasePath + "/#/taskInfo";
            }
        }
    });
    //省、市联动
    showLocation();
    var output = [];
    $.ajax({
        type : "POST",
        url : BasePath + "/user/queryUser.do",
        data: {},
        dataType : "json",
        success : function(data) {
            if (data.retCode == SUCCESS) {
                var list = data.result;
                for ( var i = 0; i < list.length; i++) {
                    var companyname = list[i].companyname;
                    if(companyname==null){
                        companyname = "无企业";
                    }
                    output.push('<option value="' + list[i].userid + '">' + list[i].username + ' - ' + companyname + ' - ' + list[i].rolename + '</option>');
                }
                $(".select2").html(output.join(''));
                $(".select2").select2({
                    width: '100%'
                });
                $("#onload").attr("style", "display:none;");
                $("#panel-body").attr("style", "display:block;");
            } else {
                messageDanger("执行人员列表暂无数据", data.retMessage);
                location.href = BasePath + "/#/creatTask";
            }
        }
    });
    $scope.save = function(taskInfo) {
        $("#submit").attr("disabled", true);
        var executor="";
        $(".select2 option:selected").each(function() {
            executor += $(this).attr("value");
        });
        $.ajax({
            type : "POST",
            url : BasePath + "/task/addTask.do",
            data : {
                'executor':executor,
                'name':taskInfo.name,
                'province':$('#province').val(),
                'city':$('#city').val(),
                'operator':taskInfo.operator,
                'totaltimes':taskInfo.totaltimes
            },
            dataType : "json",
            success : function(data) {
                if (data.retCode == SUCCESS) {
                    successAlert();
                    location.href = BasePath + "/#/taskInfo";
                } else{
                    messageDanger("创建任务失败", data.retMessage);
                }
                $("#submit").removeAttr("disabled");
            }
        });
    };
    $scope.reset = function() {
        $scope.taskInfo = {};
        $('#province').val('');
        $('#city').val('');
        $('#loc_city').empty();
        $('#loc_city').append('<option value="">地级市</option>');
    };
}]);
/**
 * 任务下靶机信息
 */
bracketCtrls.controller('task4TargetInfo',['$scope', function($scope, $http) {
    if(checkRole('#/task4TargetInfo,','taskManage')){
        return;
    }
    var taskid = sessionStorage.getItem("taskid4TargetInfo");
    var tasktype = sessionStorage.getItem("tasktype4TargetInfo");
    if(taskid == null || taskid == "" || tasktype == null || tasktype == ""){
        location.href = BasePath + "/#/main";
        return;
    }
    $("#taskName").html('<font size="3px;"color="#1D2939">'+sessionStorage.getItem("taskName4TargetInfo")+'</font> 任务下的靶机信息');
    //
    $('.leftpanel').hide();
    $('.mainpanel').attr('style','margin-left:0px;padding-top:0px;');
    $('.headerbar').hide();
    //
    var columns = [{
        field : 'location',
        title : '地区',
        align : 'center',
        valign : 'middle'
    }, {
        field : 'operator',
        title : '运营商',
        align : 'center',
        valign : 'middle'
    }, {
        field : 'ip',
        title : 'IP地址',
        align : 'center',
        valign : 'middle'
    }, {
        field : 'targetport',
        title : '端口',
        align : 'center',
        valign : 'middle'
    } ];
    if(checkElement('addTargetByTask,')){
        $('#addTargetByTask').attr("style","width: 110px;padding-bottom: 10px;display:block;");
    }
    if(!(tasktype == "初始" || tasktype == "下发失败")){
        columns.push({
            field : 'state',
            title : '部署状态',
            align : 'center',
            valign : 'middle'
        });
    }else if(checkElement('deleteTargetByTask,')){
        columns.push({
            title : '操作',
            align : 'center',
            valign : 'middle',
            formatter : operateFormatterForTaskTarget,
            events : operateEventsForTaskTarget
        });
        $scope.del = function() {
            $.ajax({
                type : "POST",
                url : BasePath+ "/taskTarget/delete.do",
                data : {
                    'taskid' : taskid,
                    'targetid' : sessionStorage.getItem("taskTargetid4DeleteTarget")
                },
                dataType : "json",
                success : function(data) {
                    if (data.retCode == SUCCESS) {
                        successAlert();
                        $('#datatable').bootstrapTable('refresh',{url : BasePath+ '/taskTarget/query.do?taskid='+ taskid});
                    } else {
                        messageDanger("删除靶机失败", data.retMessage);
                    }
                }
            });
        };
    }
    $('#datatable').bootstrapTable({
        method : 'post',
        url : BasePath+ '/taskTarget/query.do?taskid='+ taskid,
        cache : false,
        striped : true,
        sidePagination : 'server',
        pagination : true,
        pageSize : 10,
        pageList : [ 10, 25, 50, 100,200 ],
        showColumns : true,
        showRefresh : true,
        minimumCountColumns : 2,
        onLoadError: SessionTimeOut,
        columns : columns
    });
} ]);
/**
 * 任务添加靶机
 */
bracketCtrls.controller('creatTask4Target', ['$scope','$http', function($scope, $http) {
    if(checkRole('#/creatTask4Target,','taskManage')){
        return;
    }
    var taskid = sessionStorage.getItem("taskid4TargetInfo");
    if(taskid == null || taskid == ""){
        location.href = BasePath + "/#/main";
        return ;
    }
    $("#taskName").html('<font size="3px;"color="#1D2939">'+sessionStorage.getItem("taskName4TargetInfo")+'</font> 任务下添加靶机');
    var output = [];
    $.ajax({
        type : "POST",
        url : BasePath + "/target/queryTargetByStateAndIds.do",
        data : {'taskid':taskid,},
        dataType : "json",
        success : function(data) {
            if (data.retCode == SUCCESS) {
                var list = data.result;
                for ( var i = 0; i < list.length; i++) {
                    output.push('<option value="' + list[i].id + '">'
                        + list[i].location +' - '+list[i].operator+' - '+list[i].ip +':'+list[i].targetport+ '</option>');
                }
                $(".select2").html(output.join(''));
                $(".select2").select2();
                $(".select2").width("100%");
                $("#onload").attr("style", "display:none;");
                $("#panel-body").attr("style", "display:block;");
            } else {
                messageDanger("靶机列表暂无数据", data.retMessage);
                location.href = BasePath + "/#/task4TargetInfo";
            }
        }
    });
    $scope.save = function() {
        $("#submit").attr("disabled", true);
        var ids = "";
        $(".select2 option:selected").each(function() {
            ids += $(this).attr("value") + ",";
        });
        ids = ids.substring(0, ids.length - 1);
        if(ids == ""){
            messageDanger("添加靶机失败", "未选择靶机!");
            $("#submit").removeAttr("disabled");
            return ;
        }
        $.ajax({
            type : "POST",
            url : BasePath + "/taskTarget/add.do",
            data : {'taskid':taskid,'ids':ids},
            dataType : "json",
            success : function(data) {
                if (data.retCode == SUCCESS) {
                    successAlert();
                    location.href = BasePath+ "/#/task4TargetInfo";
                } else{
                    messageDanger("添加靶机失败", data.retMessage);
                }
                $("#submit").removeAttr("disabled");
            }
        });
    };
} ]);
/**
 * 任务下样本库信息
 */
bracketCtrls.controller('task4SampleBankInfo',['$scope', function($scope, $http) {
    if(checkRole('#/task4SampleBankInfo,','taskManage')){
        return;
    }
    var taskid = sessionStorage.getItem("taskid4SampleInfo");
    var tasktype = sessionStorage.getItem("tasktype4SampleInfo");
    if(taskid == null || taskid == "" || tasktype == null || tasktype == ""){
        location.href = BasePath + "/#/main";
        return;
    }
    $("#taskName").html('<font size="3px;"color="#1D2939">'+sessionStorage.getItem("taskName4SampleInfo")+'</font> 任务下的样本库信息');
    //
    $('.leftpanel').hide();
    $('.mainpanel').attr('style','margin-left:0px;padding-top:0px;');
    $('.headerbar').hide();
    //
    var columns = [{
        field : 'bankname',
        title : '样本库名',
        align : 'center',
        valign : 'middle'
    }, {
        field : 'type',
        title : '样本库类型',
        align : 'center',
        valign : 'middle'
    } ];
    if(checkElement('addSampleBankByTask,')){
        $('#addSampleBankByTask').attr("style","width: 120px;padding-bottom: 10px;display:block;");
    }
    if((tasktype =='初始' || tasktype =='下发失败') && checkElement('deleteSampleBankByTask,')){
        columns.push({
            title : '操作',
            align : 'center',
            valign : 'middle',
            formatter : operateFormatterTask4SampleBank,
            events : operateEventsForTask4SampleBank
        });
        $scope.del = function() {
            $.ajax({
                type : "POST",
                url : BasePath+ "/taskSamplebank/delete.do",
                data : {
                    'taskid' : taskid,
                    'samplebankid' : sessionStorage.getItem("samplebankid4DeleteSampleBank")
                },
                dataType : "json",
                success : function(data) {
                    if (data.retCode == SUCCESS) {
                        successAlert();
                        $('#datatable').bootstrapTable('refresh',{url : BasePath+ '/taskSamplebank/queryTaskSamplebank.do?taskid='+ taskid});
                    } else {
                        messageDanger("删除样本库失败", data.retMessage);
                    }
                }
            });
        };
    }
    $('#datatable').bootstrapTable({
        method : 'post',
        url : BasePath+ '/taskSamplebank/queryTaskSamplebank.do?taskid='+ taskid,
        cache : false,
        striped : true,
        sidePagination : 'server',
        pagination : true,
        pageSize : 10,
        pageList : [ 10, 25, 50, 100,200 ],
        showColumns : true,
        showRefresh : true,
        minimumCountColumns : 2,
        onLoadError: SessionTimeOut,
        columns : columns
    });
} ]);
/**
 * 个人信息
 */
bracketCtrls.controller('personalInfo', [ '$scope', function($scope) {
    window.clearTimeout(time);
    $scope.personalInfo = {
        loginname:sessionStorage.getItem("loginName"),
        username:sessionStorage.getItem("loginUserName"),
        mobilephone:sessionStorage.getItem("loginPhone"),
        email:sessionStorage.getItem("loginEmail"),
        rolename:sessionStorage.getItem("loginRoleName"),
        companyname:sessionStorage.getItem("loginCompanyName")
    };
} ]);
/**
 * 修改用户密码
 */
bracketCtrls.controller('editUserPassword', [ '$scope', '$http', function($scope, $http) {
    window.clearTimeout(time);
    $scope.save = function(editUserPassword) {
        if(editUserPassword.newPWD!=editUserPassword.newPWD2){
            messageDanger("修改密码失败", "确认密码与新密码不一致！");
            return;
        }
        $("#submit").attr("disabled", true);
        $.ajax({
            type : "POST",
            url : BasePath + "/user/editUserPassword.do",
            data: editUserPassword,
            dataType : "json",
            success : function(data) {
                if (data.retCode == SUCCESS) {
                    successAlert();
                    location.href = BasePath+ "/#/main";
                } else {
                    messageDanger("修改密码失败", data.retMessage);
                }
                $("#submit").removeAttr("disabled");
            }
        });
    };
    $scope.reset = function() {
        $scope.editUserPassword = {};
    };
} ]);
/**
 * 任务添加样本库
 */
bracketCtrls.controller('addTaskSampleBank', ['$scope','$http', function($scope, $http) {
    if(checkRole('#/addTaskSampleBank,','taskManage')){
        return;
    }
    var taskid = sessionStorage.getItem("taskid4SampleInfo");
    if(taskid == null || taskid == ""){
        location.href = BasePath + "/#/main";
        return ;
    }
    $("#taskName").html('<font size="3px;"color="#1D2939">'+sessionStorage.getItem("taskName4SampleInfo")+'</font> 任务下添加样本库');
    var output = [];
    $.ajax({
        type : "POST",
        url : BasePath + "/taskSamplebank/selectSampleBank.do",
        data : {
            'taskid' : taskid
        },
        dataType : "json",
        success : function(data) {
            if (data.retCode == SUCCESS) {
                var list = data.result;
                for ( var i = 0; i < list.length; i++) {
                    var type;
                    if(list[i].type=="cmcc"){
                        type='移动互联网疑似病毒样本';
                    }else{
                        type='木马和僵尸网络病毒样本';
                    }
                    output.push('<option value="' + list[i].id + '">'
                        + list[i].bankname + ' - '
                        + type + '</option>');
                }
                $(".select2").html(output.join(''));
                $(".select2").select2({
                    width: '100%'
                });
                $("#onload").attr("style", "display:none;");
                $("#panel-body").attr("style", "display:block;");
            } else{
                messageDanger("样本库列表暂无数据", data.retMessage);
                location.href = BasePath + "/#/task4SampleBankInfo";
            }
        }
    });
    $scope.save = function() {
        $("#submit").attr("disabled", true);
        var ids = "";
        $(".select2 option:selected").each(function() {
            ids += $(this).attr("value") + ",";
        });
        ids = ids.substring(0, ids.length - 1);
        if(ids == ""){
            messageDanger("添加样本库失败", "未选择样本库!");
            $("#submit").removeAttr("disabled");
            return;
        }
        $.ajax({
            type : "POST",
            url : BasePath + "/taskSamplebank/addSampleBank.do",
            data : {
                'taskid' : taskid,
                'ids' : ids
            },
            dataType : "json",
            success : function(data) {
                if (data.retCode == SUCCESS) {
                    successAlert();
                    location.href = BasePath + "/#/task4SampleBankInfo";
                }else{
                    messageDanger("添加样本库失败", data.retMessage);
                }
                $("#submit").removeAttr("disabled");
            }
        });
    };
}]);
/**
 * 拨测客户端信息
 */
bracketCtrls.controller('clientInfo',['$scope', function($scope, $http) {
    if(checkRole('#/clientInfo,','clientManage')){
        return;
    }
    if(checkElement('uploadClient,')){
        $('#uploadClient').attr("style","width: 130px;padding-bottom: 10px;display:block;");
    }
    var columns = [{
        field : 'filename',
        title : '文件名',
        align : 'center',
        valign : 'middle'
    },	{
        field : 'version',
        title : '版本',
        align : 'center',
        valign : 'middle'
    },	{
        field : 'uploadtimeStr',
        title : '上传时间',
        align : 'center',
        valign : 'middle'
    },  {
        field : 'remark',
        title : '备注',
        align : 'center',
        valign : 'middle'
    }  ];
    if(checkElement('downloadClient,')){
        columns.push({
            title : '操作',
            align : 'center',
            valign : 'middle',
            formatter : operateFormatterForClient
        });
    }
    $('#datatable').bootstrapTable({
        method : 'post',
        url : BasePath+ '/client/query.do',
        cache : false,
        striped : true,
        sidePagination : 'server',
        pagination : true,
        pageSize : 10,
        pageList : [ 10, 25, 50, 100,200 ],
        showColumns : true,
        showRefresh : true,
        minimumCountColumns : 2,
        onLoadError: SessionTimeOut,
        columns : columns
    });
} ]);
/**
 * 上传拨测工具
 */
bracketCtrls.controller('uploadFile',['$scope', function($scope, $http) {
    if(checkRole('#/uploadFile,','clientManage')){
        return;
    }
    $scope.save = function(clientInfo) {
        if($("#file1").val()==""){
            messageDanger("上传拨测客户端失败", "未选择任何文件!");
            return;
        }
        $("#submit").attr("disabled", true);
        $.ajaxFileUpload({
            url : BasePath + "/client/upload.do",
            data : clientInfo,
            dataType : "json",
            secureuri: false, //是否需要安全协议，一般设置为false
            fileElementId: 'file1', //文件上传域的ID
            success : function(data) {
                if(data.retCode == SUCCESS){
                    successAlert();
                    location.href = BasePath + "/#/clientInfo";
                }else{
                    messageDanger("上传拨测客户端失败", data.retMessage);
                }
                $("#submit").removeAttr("disabled");
            }
        });
    };
    $scope.reset = function() {
        $scope.clientInfo = {};
    };
} ]);



/**
 * 拨测软件包信息
 */
bracketCtrls.controller('packageInfo',['$scope', function($scope, $http) {
    if(checkRole('#/packageInfo,','clientManage')){
        return;
    }
    if(checkElement('uploadPackage,')){
        $('#uploadPackage').attr("style","width: 130px;padding-bottom: 10px;display:block;");
    }
    var columns = [{
        field : 'filename',
        title : '文件名',
        align : 'center',
        valign : 'middle'
    },	{
        field : 'version',
        title : '版本',
        align : 'center',
        valign : 'middle'
    },	{
        field : 'uploadtimeStr',
        title : '上传时间',
        align : 'center',
        valign : 'middle'
    },  {
        field : 'remark',
        title : '备注',
        align : 'center',
        valign : 'middle'
    }  ];
    if(checkElement('downloadPackage,')){
        columns.push({
            title : '操作',
            align : 'center',
            valign : 'middle',
            formatter : operateFormatterForClient2
        });
    }
    $('#datatable').bootstrapTable({
        method : 'post',
        url : BasePath+ '/package/query.do',
        cache : false,
        striped : true,
        sidePagination : 'server',
        pagination : true,
        pageSize : 10,
        pageList : [ 10, 25, 50, 100,200 ],
        showColumns : true,
        showRefresh : true,
        minimumCountColumns : 2,
        onLoadError: SessionTimeOut,
        columns : columns
    });
} ]);
/**
 * 上传软件包工具
 */
bracketCtrls.controller('packageUpload',['$scope', function($scope, $http) {
    if(checkRole('#/packageUpload,','clientManage')){
        return;
    }
    $scope.save = function(packageInfo) {
        if($("#file1").val()==""){
            messageDanger("上传拨测客户端失败", "未选择任何文件!");
            return;
        }
        $("#submit").attr("disabled", true);
        $.ajaxFileUpload({
            url : BasePath + "/package/upload.do",
            data : packageInfo,
            dataType : "json",
            secureuri: false, //是否需要安全协议，一般设置为false
            fileElementId: 'file1', //文件上传域的ID
            success : function(data) {
                if(data.retCode == SUCCESS){
                    successAlert();
                    location.href = BasePath + "/#/packageInfo";
                }else{
                    messageDanger("上传拨测客户端失败", data.retMessage);
                }
                $("#submit").removeAttr("disabled");
            }
        });
    };
    $scope.reset = function() {
        $scope.clientInfo = {};
    };
} ]);




/**
 * 拨测结果信息
 */
bracketCtrls.controller('taskresultInfo',['$scope', function($scope, $http) {
    if(checkRole('#/taskresultInfo,','taskManage')){
        return;
    }
    var columns = [{
        field : 'taskname',
        title : '任务名',
        align : 'center',
        valign : 'middle'
    },  {
        field : 'province',
        title : '拨测地区',
        align : 'center',
        valign : 'middle'
    },  {
        field : 'operator',
        title : '运营商',
        align : 'center',
        valign : 'middle'
    }, {
        field : 'executor',
        title : '执行人员',
        align : 'center',
        valign : 'middle'
    }, {
        field : 'resultnumber',
        title : '总样本数',
        align : 'center',
        valign : 'middle'
    }, {
        field : 'hitpercent',
        title : '命中率',
        align : 'center',
        valign : 'middle'
    }, {
        field : 'misreportpercent',
        title : '错报率',
        align : 'center',
        valign : 'middle'
    }, {
        field : 'falsepercent',
        title : '误报率',
        align : 'center',
        valign : 'middle'
    }, {
        field : 'percent',
        title : '成功率',
        align : 'center',
        valign : 'middle'
    } ];
    if(checkElement('checkResults,')){
        columns.push({
            title : '操作',
            align : 'center',
            valign : 'middle',
            formatter : operateFormatterForTaskresult,
            events : operateEventsForTaskresult
        });
    }
    if(checkElement('uploadCheckList,')){
        $('#uploadCheckList').attr("style","display:block;");
    }
    if(checkElement('uploadLogs,')){
        $('#uploadLogs').attr("style","display:block;");
    }
    $('#datatable').bootstrapTable({
        method : 'post',
        url : BasePath+ '/taskresult/query.do',
        cache : false,
        striped : true,
        sidePagination : 'server',
        pagination : true,
        pageSize : 10,
        pageList : [ 10, 25, 50, 100,200 ],
        showColumns : true,
        showRefresh : true,
        minimumCountColumns : 2,
        onLoadError: SessionTimeOut,
        columns : columns
    });
} ]);
/**
 * 上传运营商检测列表
 */
bracketCtrls.controller('uploadOperatorCheckList',['$scope', function($scope, $http) {
    if(checkRole('#/uploadOperatorCheckList,','taskManage')){
        return;
    }
    var output = [];
    $.ajax({
        type : "POST",
        url : BasePath + "/task/getTask4UploadOperCheckList.do",
        data : {},
        dataType : "json",
        success : function(data) {
            if (data.retCode == SUCCESS) {
                var list = data.result;
                for ( var i = 0; i < list.length; i++) {
                    output.push('<option value="' + list[i].id + '" name="' + list[i].name + '">'
                        + list[i].name + ' - ' + list[i].executor + '</option>');
                }
                $(".select2").html(output.join(''));
                $(".select2").select2();
                $(".select2").width("100%");
                $("#onload").attr("style", "display:none;");
                $("#panel-body").attr("style", "display:block;");
            } else {
                messageDanger("进行中任务列表暂无数据", data.retMessage);
                location.href = BasePath + "/#/taskresultInfo";
            }
        }
    });
    var sampleids; //未检测ids
    var sampleids0; //恶意ids
    var sampleids1; //正常ids
    var sampleids2; //疑似ids
    var taskid;
    var resultnumber;
    var evilnumber;
    var nomalnumber;
    var likenumber;
    var uptotalnumber;
    var upevilnumber;
    var upnoamlnumber;
    var uplikenumber;
    var nottestnumber;
    var hitpercent;
    var misreportpercent;
    var falsepercent;
    $scope.save = function() {
        if($("#file1").val()==""){
            messageDanger("上传运营商检测列表失败", "请选择上传文件");
            return;
        }
        $("#submit").attr("disabled", true);
        var taskname="";
        taskid="";
        $(".select2 option:selected").each(function() {
            taskid += $(this).attr("value");
            taskname += $(this).attr("name");
        });
        $.ajaxFileUpload({
            url : BasePath + "/taskresult/upload.do",
            data : {'taskid':taskid},
            dataType : "json",
            secureuri: false, //是否需要安全协议，一般设置为false
            fileElementId: 'file1', //文件上传域的ID
            success : function(data) {
                if(data.retCode==SUCCESS){
                    sampleids=data.result.sampleids;
                    sampleids0=data.result.sampleids0;
                    sampleids1=data.result.sampleids1;
                    sampleids2=data.result.sampleids2;
                    resultnumber=data.result.resultnumber;
                    evilnumber = data.result.countevil;
                    nomalnumber = data.result.countnomal;
                    likenumber = data.result.countlike;
                    uptotalnumber = data.result.uptotalnumber;
                    upevilnumber= data.result.upevilnumber;
                    upnoamlnumber= data.result.upnoamlnumber;
                    uplikenumber = data.result.uplikenumber;
                    nottestnumber=data.result.nottestnumber;
                    hitpercent = data.result.hitpercent;
                    misreportpercent= data.result.misreportpercent;
                    falsepercent = data.result.falsepercent;
                    $('#showDialog').click();
                    $('#name').html(taskname);
                    $('#count').html(resultnumber);
                    $('#countevil').html(evilnumber);
                    $('#countnomal').html(nomalnumber);
                    $('#countlike').html(likenumber);
                    $('#uptotal').html(uptotalnumber);
                    $('#upevil').html(upevilnumber);
                    $('#upnoaml').html(upnoamlnumber);
                    $('#uplike').html(uplikenumber);
                    $('#count4NoCheck').html(nottestnumber);
                    $('#falsenumber').html(data.result.falsenumber);
                    $('#hitpercent').html(hitpercent);
                    $('#misreportpercent').html(misreportpercent);
                    $('#falsepercent').html(falsepercent);
                    $('#list').html(data.result.html);
                    $('#list0').html(data.result.html0);
                    $('#list1').html(data.result.html1);
                    $('#list2').html(data.result.html2);
                    $('table').addClass("table table-hover table-striped");
                    $('th').attr("style","text-align: center; vertical-align: middle; ");
                    $('td').attr("style","text-align: center; vertical-align: middle; ");
                    $('bzd').attr("style","background-color:#428bca;color:white;text-align: center;");
                } else {
                    messageDanger("上传运营商检测列表失败", data.retMessage);
                }
                $("#submit").removeAttr("disabled");
            }
        });
    };
    $scope.saveResult = function() {
        $.ajax({
            type : "POST",
            url : BasePath + "/taskresult/saveResult.do",
            data: {'taskid':taskid,
                'resultnumber':resultnumber,
                'evilnumber':evilnumber,
                'nomalnumber':nomalnumber,
                'likenumber':likenumber,
                'uptotalnumber':uptotalnumber,
                'upevilnumber':upevilnumber,
                'upnoamlnumber':upnoamlnumber,
                'uplikenumber':uplikenumber,
                'nottestnumber':nottestnumber,
                'hitpercent':hitpercent,
                'misreportpercent':misreportpercent,
                'falsepercent':falsepercent,
                'sampleids':sampleids,
                'sampleids0':sampleids0,
                'sampleids1':sampleids1,
                'sampleids2':sampleids2
            },
            dataType : "json",
            success : function(data) {
                if (data.retCode == SUCCESS) {
                    successAlert();
                    location.href = BasePath+ "/#/taskresultInfo";
                } else {
                    messageDanger("保存拨测任务结果失败", data.retMessage);
                }
            }
        });
    };
} ]);
/**
 * 检测列表详细结果
 */
bracketCtrls.controller('taskresultdetailInfo',['$scope', function($scope, $http) {
    if(checkRole('#/taskresultdetailInfo,','taskManage')){
        return;
    }
    var taskresultid = sessionStorage.getItem("taskresultid");
    $("#taskName").html('<font size="3px;"color="#1D2939">'+sessionStorage.getItem("taskName")+'</font> 任务的拨测结果详细信息');
    $('#datatable').bootstrapTable({
        method : 'post',
        url : BasePath+ '/taskresult/query.do?taskresultid='+ taskresultid,
        cache : false,
        striped : true,
        sidePagination : 'server',
        pagination : true,
        pageSize : 10,
        pageList : [ 10, 25, 50, 100,200 ],
        showColumns : true,
        showRefresh : true,
        minimumCountColumns : 2,
        onLoadError: SessionTimeOut,
        columns : [
//			            {
//				field : 'resultnumber',
//				title : '任务-样本总数',
//				align : 'center',
//				valign : 'middle'
//			},
            {
                field : 'evilnumber',
                title : '任务-恶意样本数',
                align : 'center',
                valign : 'middle'
            }, {
                field : 'normalnumber',
                title : '任务-正常样本数',
                align : 'center',
                valign : 'middle'
            },{
                field : 'likenumber',
                title : '任务-疑似样本数',
                align : 'center',
                valign : 'middle'
            },
//			{
//				field : 'uptotalnumber',
//				title : '检测-样本总数',
//				align : 'center',
//				valign : 'middle'
//			},
            {
                field : 'upevilnumber',
                title : '检测-恶意样本数',
                align : 'center',
                valign : 'middle',
                formatter : operateFormatterForUpevilnumber,
                events : operateEventsForUpevilnumber
            }, {
                field : 'upnormalnumber',
                title : '检测-正常样本数',
                align : 'center',
                valign : 'middle',
                formatter : operateFormatterForUpnormalnumber,
                events : operateEventsForUpnormalnumber
            }, {
                field : 'uplikenumber',
                title : '检测-疑似样本数',
                align : 'center',
                valign : 'middle',
                formatter : operateFormatterForUplikenumber,
                events : operateEventsForUplikenumber
            }, {
                field : 'falsenumber',
                title : '检测-错误样本数',
                align : 'center',
                valign : 'middle'
            }, {
                field : 'nottestnumber',
                title : '任务未检测恶意样本数',
                align : 'center',
                valign : 'middle',
                formatter : operateFormatterForNottestnumber,
                events : operateEventsForNottestnumber
            }]
    });
} ]);
/**
 * DDOSTOOL信息
 */
bracketCtrls.controller('ddosToolInfo', [ '$scope', function($scope, $http) {
    if(checkRole('#/ddosToolInfo,','ddosManage')){
        return;
    }
    //省、市联动
    showLocation();
    var columns = [ {
        title : '实时状态',
        align : 'center',
        valign : 'middle',
        formatter : operateFormatterForEditDdos2
    }, {
        field : 'location',
        title : '地区',
        align : 'center',
        valign : 'middle'
    }, {
        field : 'shefip',
        title : '攻击端IP',
        align : 'center',
        valign : 'middle'
    }, {
        field : 'user',
        title : '用户名',
        align : 'center',
        valign : 'middle'
    }, {
        field : 'arrangestate',
        title : '部署状态',
        align : 'center',
        valign : 'middle'
    } ];
    if(checkElement('logoutDdosTool,')){
        columns.push({
            title : '启用/禁用',
            align : 'center',
            valign : 'middle',
            formatter : operateFormatterForDdosInfo
        });
        function updateState(id, state) {//更新攻击端状态
            $.ajax({
                type : "POST",
                url : BasePath + "/DdosTool/updateState.do",
                data : {
                    'id' : id,
                    'state' : state
                },
                dataType : "json",
                success : function(data) {
                    if (data.retCode == SUCCESS) {
                        successAlert();
                    } else {
                        messageDanger("更新攻击端状态失败", data.retMessage);
                    }
                    $('#datatable').bootstrapTable('refresh',{url : BasePath+ '/DdosTool/queryDdosTool.do'});
                }
            });
        }
    }
    if(checkElement('checkDdosTask,') || checkElement('editDdosTool,') || checkElement('arrangeDdosTool')
        || checkElement('uninstallDdosTool,') || checkElement('supervisoryDdos') || checkElement('historySupervisoryDdos')){
        columns.push({
            title : '操作',
            align : 'center',
            valign : 'middle',
            formatter : operateFormatterForEditDdos,
            events : operateEventsForDdos
        });
    }
    if(checkElement('addDdosTool,')){
        $('#addDdosTool').attr("style","width: 120px;padding-bottom: 10px;display:block;");
    }
    $('#datatable').bootstrapTable({
        method : 'post',
        url : BasePath + '/DdosTool/queryDdosTool.do',
        cache : false,
        striped : true,
        sidePagination : 'server',
        pagination : true,
        pageSize : 10,
        pageList : [ 10, 25, 50, 100, 200 ],
        showColumns : true,
        showRefresh : true,
        minimumCountColumns : 2,
        onLoadSuccess : function() {
            for ( var i = 0; i < $('.toggle').length; i++) {
                $('.toggle').eq(i).toggles({
                    on : !$('.toggle').eq(i).hasClass('toggle-off')
                });
            }
            $('.toggle').on('toggle', function(e, active) {
                var id = $(this).attr('id');
                if (active) {
                    updateState(id , "0");
                } else {
                    updateState(id , "1");
                }
            });
            nowState("/DdosTool/getHeartbeat.do");
        },
        onLoadError: SessionTimeOut,
        columns : columns
    });

    //根据ID和地区模糊查询
    $('#ddosToolSearch').click(function () {
        var shefip = encodeURIComponent($("#shefip").val());
        var state = encodeURIComponent($("#state").val());
        var province = encodeURIComponent($('#province').val());
        var city = encodeURIComponent($('#city').val());
        $('#datatable').bootstrapTable('refresh', {url: BasePath+'/DdosTool/queryDdosTool.do?shefip='+shefip
            +'&state='+state+'&province='+province+'&city='+city});
    });
} ]);
/**
 * 创建攻击端
 */
bracketCtrls.controller('creatDdosTool', [ '$scope', '$http', function($scope, $http) {
    if(checkRole('#/creatDdosTool,','ddosManage')){
        return;
    }
    //省、市联动
    showLocation();
    $scope.save = function(ddosToolInfo) {
        $("#submit").attr("disabled", true);
        $.ajax({
            type : "POST",
            url : BasePath + "/DdosTool/add.do",
            data : {'shefip':ddosToolInfo.shefip
                ,'province':$('#province').val()
                ,'city':$('#city').val()
                ,'password':ddosToolInfo.password},
            dataType : "json",
            success : function(data) {
                if (data.retCode == SUCCESS) {
                    successAlert();
                    location.href = BasePath + "/#/ddosToolInfo";
                } else {
                    messageDanger("创建攻击端失败", data.retMessage);
                }
                $("#submit").removeAttr("disabled");
            }
        });
    };
    $scope.reset = function() {
        $scope.ddosToolInfo = {};
        $('#province').val('');
        $('#city').val('');
        $('#loc_city').empty();
        $('#loc_city').append('<option value="">地级市</option>');
    };
} ]);
/**
 * 修改攻击端基本信息
 */
bracketCtrls.controller('editDdosTool', [ '$scope', '$http', function($scope, $http) {
    if(checkRole('#/editDdosTool,','ddosManage')){
        return;
    }
    var id = sessionStorage.getItem("id4EditDdos");
    var location1 = sessionStorage.getItem("location4EditDdos");
    var shefip = sessionStorage.getItem("shefip4EditDdos");
    var user = sessionStorage.getItem("user4EditDdos");
    var password = sessionStorage.getItem("password4EditDdos");
    var arrangestate = sessionStorage.getItem("arrangestate4EditDdos");
    if(id == null || id ==""){
        location.href=  BasePath + "/#/main";
        return;
    }
    $("#ddosToolName").html('修改IP为  <font size="3px;"color="#1D2939">'+shefip+'</font> 的攻击端信息');
    //省、市联动
    showLocation();
    var province="",city="";
    if(location1.indexOf(" - ")>0){
        province = location1.substring(0,location1.indexOf(" "));
        city = location1.substring(location1.indexOf("-")+2,location1.length);
    }else{
        province = location1;
    }
    $scope.ddosInfo = {
        id : id,
        shefip : shefip,
        user : user,
        password : password,
        arrangestate : arrangestate,
    };
    $('#oldProvince').html(province);
    if(city==""){
        $('#oldCity').html("-无-");
    }else{
        $('#oldCity').html(city);
    }
    $('#city').val(city);
    $('#province').val(province);
    $scope.save = function(ddosInfo) {
        $("#submit").attr("disabled", true);
        if($('#province').val()!=null && $('#province').val()!=""){
            province = $('#province').val();
            city = $('#city').val();
        }
        ddosInfo.province = province;
        ddosInfo.city = city;
        $.ajax({
            type : "POST",
            url : BasePath + "/DdosTool/update.do",
            data : ddosInfo,
            dataType : "json",
            success : function(data) {
                if (data.retCode == SUCCESS) {
                    successAlert();
                    location.href = BasePath + "/#/ddosToolInfo";
                } else {
                    messageDanger("修改攻击端基本信息失败", data.retMessage);
                }
                $("#submit").removeAttr("disabled");
            }
        });
    };
    $scope.reset = function() {
        $scope.ddosInfo = {
            id : id,
            shefip : shefip,
            user : user,
            password : password,
            arrangestate : arrangestate,
        };
        $('#loc_province').val("");
        $('#province').val(province);
        $('#city').val(city);
        $('#loc_city').empty();
        $('#loc_city').append('<option value="">地级市</option>');
        $('#operator').val("");
    };
} ]);
/**
 * 创建DDOS任务
 */
bracketCtrls.controller('creatDdosTask', ['$scope','$http',function($scope, $http) {
    if(checkRole('#/creatDdosTask,','taskManage')){
        return;
    }
    $('#datepicker').datepicker();
    $('#datepicker-inline').datepicker();
    $('#datepicker-multiple').datepicker({
        numberOfMonths: 3,
        showButtonPanel: true
    });
    $('#timepicker2').timepicker({showMeridian: false});
    $('#datepicker').val(new Date().toLocaleDateString());
    var t = new Date();
    t.setTime(new Date().getTime()+10*60*1000);
    $('#timepicker2').val(t.getHours()+":"+t.getMinutes());

    $('#attacktype').change(function () {
        var attacktype = $('#attacktype').val();
        $('#targetip').val('');
        if(attacktype == "CC"){
            $('#targetip').removeAttr("disabled");
            $('#targetipText').html("请输入正确的攻击地址, 如http://hl-tec.com、http://127.0.0.1:8080");
        }else if(attacktype == "SYN"){
            $('#targetip').removeAttr("disabled");
            $('#targetipText').html("请输入正确的攻击地址, 如http://hl-tec.com、http://127.0.0.1:8080");
        }else if(attacktype == "UDP"){
            $('#targetip').removeAttr("disabled");
            $('#targetipText').html("请输入正确的攻击地址, 如127.0.0.1:123");
        }else{
            $('#targetip').attr("disabled",true);
            $('#targetipText').html("请先选择攻击类型");
        }
    });
    /*ip号校验*/
    function isIP(ip) {
        var reSpaceCheck = /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/;
        if (reSpaceCheck.test(ip))
        {
            ip.match(reSpaceCheck);
            if (RegExp.$1<=255&&RegExp.$1>=0
                &&RegExp.$2<=255&&RegExp.$2>=0
                &&RegExp.$3<=255&&RegExp.$3>=0
                &&RegExp.$4<=255&&RegExp.$4>=0)
            {
                return true;
            }else
            {
                return false;
            }
        }else
        {
            return false;
        }
    }
    /*端口号校验*/
    function isPort(str) {
        var parten=/^(\d)+$/g;
        if(parten.test(str)&&parseInt(str)<=65535&&parseInt(str)>=0){
            return true;
        }else{
            return false;
        }
    }
    $scope.save = function(ddosTaskInfo) {
        if(ddosTaskInfo.attacktype == "CC"){
            if(ddosTaskInfo.targetip.indexOf("http://") == -1){
                messageDanger("系统提示","攻击地址输入错误!");
                return;
            }
        }else if(ddosTaskInfo.attacktype == "SYN"){
            if(ddosTaskInfo.targetip.indexOf("http://") == -1){
                messageDanger("系统提示","攻击地址输入错误!");
                return;
            }
        }else if(ddosTaskInfo.attacktype == "UDP"){
            var arr = ddosTaskInfo.targetip.split(":");
            if(arr.length != 2){
                messageDanger("系统提示","攻击地址输入错误!");
                return;
            }
            var ip = arr[0];
            var port = arr[1];
            if(!isIP(ip)){
                messageDanger("系统提示","攻击地址输入错误!");
                return;
            }
            if(!isPort(port)){
                messageDanger("系统提示","攻击地址输入错误!");
                return;
            }
        }else{
            messageDanger("系统提示","无效的请求!");
            return;
        }
        /*时间范围*/
        var timeStr=$('#datepicker').val();
        var starttime = timeStr.replace(/[\\\/]/g,"-")+" "+$('#timepicker2').val()+":00";
        if(Date.parse(starttime)<new Date().getTime()){
            messageDanger("创建任务失败", "开始时间必须大于当前系统时间!");
            return;
        }
        $("#submit").attr("disabled", true);
        $.ajax({
            type : "POST",
            url : BasePath + "/ddostask/addDdosTask.do",
            data : {
                'name' : ddosTaskInfo.name,
                'attacktime' : ddosTaskInfo.attacktime,
                'starttime' : starttime,
                'targetip' : ddosTaskInfo.targetip,
                'attacktype' : ddosTaskInfo.attacktype
            },
            dataType : "json",
            success : function(data) {
                if (data.retCode == SUCCESS) {
                    successAlert();
                    location.href = BasePath + "/#/ddosTaskInfo";
                } else {
                    messageDanger("创建任务失败", data.retMessage);
                }
                $("#submit").removeAttr("disabled");
            }
        });
    };
    $scope.reset = function() {
        $scope.ddosTaskInfo = {};
    };
} ]);
/**
 * DDOS任务信息
 */
bracketCtrls.controller('ddosTaskInfo', [ '$scope', function($scope, $http) {
    if(checkRole('#/ddosTaskInfo,','taskManage')){
        return;
    }
    $('#datepicker').datepicker();
    //省、市联动
    showLocation();
    var columns = [ {
        field : 'name',
        title : '任务名称',
        align : 'center',
        valign : 'middle'
    }, {
        field : 'targetip',
        title : '攻击地址',
        align : 'center',
        valign : 'middle'
    }, {
        field : 'starttime',
        title : '开始时间',
        align : 'center',
        valign : 'middle'
    }, {
        field : 'attacktime',
        title : '攻击时长',
        align : 'center',
        valign : 'middle'
    }, {
        field : 'attacktype',
        title : '攻击类型',
        align : 'center',
        valign : 'middle'
    }, {
        field : 'taskstate',
        title : '任务状态',
        align : 'center',
        valign : 'middle'
    } ];
    if(checkElement('manageDdosToolByDdosTask,') || checkElement('giveDdosTask,') || checkElement('okDdosTask,') || checkElement('ddosTaskCancel,')){
        columns.push({
            title : '操作',
            align : 'center',
            valign : 'middle',
            formatter : operateFormatterForDdostask,
            events : operateEventsForDdostask
        });
    }
    if(checkElement('addDdosTask,')){
        $('#addDdosTask').attr("style","width: 120px;padding-bottom: 10px;display:block;");
    }
    if(checkElement('ddosTaskCancel,')){
        $scope.back = function() {
            $.ajax({
                type : "POST",
                url : BasePath+ "/ddostask/backDdosTask.do",
                data : {
                    'taskid' : sessionStorage.getItem("ddosTaskid4BackTask")
                },
                dataType : "json",
                success : function(data) {
                    if (data.retCode == SUCCESS) {
                        successAlert();
                        $('#datatable').bootstrapTable('refresh',{url : BasePath+ '/ddostask/queryDdosTask.do'});
                    } else {
                        messageDanger("撤销任务失败", data.retMessage);
                    }
                }
            });
        };
    }
    $('#datatable').bootstrapTable({
        method : 'post',
        url : BasePath + '/ddostask/queryDdosTask.do',
        cache : false,
        striped : true,
        sidePagination : 'server',
        pagination : true,
        pageSize : 10,
        pageList : [ 10, 25, 50, 100, 200 ],
        showColumns : true,
        showRefresh : true,
        minimumCountColumns : 2,
        onLoadError: SessionTimeOut, //处理过期
        columns : columns
    });

    //模糊查询
    $('#button').click(function () {
        var name = encodeURIComponent($("#name").val());
        var targetip = encodeURIComponent($("#targetip").val());
        var attacktype = encodeURIComponent($("#attacktype").val());
        var taskstate = encodeURIComponent($("#taskstate").val());
        var startdate1 = encodeURIComponent($("#datepicker").val());
        var startdate = encodeURIComponent(startdate1.replace(/[\\\/]/g,"-"));
        var attacktime = encodeURIComponent($("#attacktime").val());
        $('#datatable').bootstrapTable('refresh',
            {url: BasePath+'/ddostask/queryDdosTask.do?name='+name+'&targetip='+targetip+'&attacktype='+attacktype+'&taskstate='+taskstate+'&startdate='+startdate+'&attacktime='+attacktime});
    });
} ]);
/**
 * DDOS任务下攻击端
 */
bracketCtrls.controller('ddosTask4ToolInfo',['$scope', function($scope, $http) {
    if(checkRole('#/ddosTask4ToolInfo,','taskManage')){
        return;
    }
    var ddostaskid = sessionStorage.getItem("ddostaskid4TargetInfo");
    var taskstate = sessionStorage.getItem("ddostaskstate4TargetInfo");
    if(ddostaskid == null || ddostaskid == "" || taskstate == null || taskstate == ""){
        location.href = BasePath + "/#/main";
        return;
    }
    $("#toolTaskame").html('<font size="3px;"color="#1D2939">'+sessionStorage.getItem("ddostaskname4TargetInfo")+'</font> 任务下的攻击端信息');
    var columns = [{
        field : 'location',
        title : '地区',
        align : 'center',
        valign : 'middle'
    }, {
        field : 'shefip',
        title : '攻击端IP',
        align : 'center',
        valign : 'middle'
    } ];
    if(taskstate == "正在下发" || taskstate == "已下发" || taskstate == "进行中" || taskstate == "已完成"){
        columns.push({
            field : 'taskstatus',
            title : '攻击状态',
            align : 'center',
            valign : 'middle'
        });
    }else if(taskstate == "撤销" || taskstate == "失效"){
        columns.push({
            field : 'taskstatus1',
            title : '下发状态',
            align : 'center',
            valign : 'middle'
        },{
            field : 'taskstatus',
            title : '攻击状态',
            align : 'center',
            valign : 'middle'
        });
    }else{
        columns.push({
            field : 'taskstatus1',
            title : '下发状态',
            align : 'center',
            valign : 'middle'
        });
        if(checkElement('deleteDdosToolByDdosTask,')){
            columns.push({
                title : '操作',
                align : 'center',
                valign : 'middle',
                formatter : operateFormatterForDdosTaskTool,
                events : operateEventsForDdosTaskTool
            });
            $scope.del = function() {
                $.ajax({
                    type : "POST",
                    url : BasePath+ "/ddosTaskTool/delete.do",
                    data : {
                        'taskid' : ddostaskid,
                        'toolid' : sessionStorage.getItem("DdosToolid4DeleteTool")
                    },
                    dataType : "json",
                    success : function(data) {
                        if (data.retCode == SUCCESS) {
                            successAlert();
                            $('#datatable').bootstrapTable('refresh',{url : BasePath+ '/ddosTaskTool/queryTool.do?taskid='+ ddostaskid});
                        } else {
                            messageDanger("删除攻击端失败", data.retMessage);
                        }
                    }
                });
            };
        }
        if(checkElement('addDdosToolByDdosTask,')){
            $('#addDdosToolByDdosTask').attr("style","width: 110px;padding-bottom: 10px;display:block;");
        }
    }
    $('#datatable').bootstrapTable({
        method : 'post',
        url : BasePath+ '/ddosTaskTool/queryTool.do?taskid='+ ddostaskid,
        cache : false,
        striped : true,
        sidePagination : 'server',
        pagination : true,
        pageSize : 10,
        pageList : [ 10, 25, 50, 100,200 ],
        showColumns : true,
        showRefresh : true,
        minimumCountColumns : 2,
        onLoadError: SessionTimeOut, //处理过期
        columns : columns
    });
} ]);
/**
 * DDOS任务添加攻击端
 */
bracketCtrls.controller('addDdosTaskTool', ['$scope','$http', function($scope, $http) {
    if(checkRole('#/addDdosTaskTool,','taskManage')){
        return;
    }
    var ddostaskid = sessionStorage.getItem("ddostaskid4TargetInfo");
    if(ddostaskid == null || ddostaskid == ""){
        location.href = BasePath + "/#/main";
        return ;
    }
    $("#ddosTaskname").html('<font size="3px;"color="#1D2939">'+sessionStorage.getItem("ddostaskname4TargetInfo")+'</font> 任务下添加攻击端');
    var output = [];
    $.ajax({
        type : "POST",
        url : BasePath + "/DdosTool/queryDoosToolByStateAndIds.do",
        data : {
            'taskid' : ddostaskid
        },
        dataType : "json",
        success : function(data) {
            if (data.retCode == SUCCESS) {
                var list = data.result;
                for ( var i = 0; i < list.length; i++) {
                    output.push('<option value="' + list[i].id + '">'
                        +'地区：'+list[i].location + ' -- '
                        +'IP：'+list[i].shefip + '</option>');
                }
                $(".select2").html(output.join(''));
                $(".select2").select2({
                    width: '100%'
                });
                $("#onload").attr("style", "display:none;");
                $("#panel-body").attr("style", "display:block;");
            } else{
                messageDanger("攻击端列表暂无数据", data.retMessage);
                location.href = BasePath + "/#/ddosTask4ToolInfo";
            }
        }
    });
    $scope.save = function() {
        $("#submit").attr("disabled", true);
        var ids = "";
        $(".select2 option:selected").each(function() {
            ids += $(this).attr("value") + ",";
        });
        ids = ids.substring(0, ids.length - 1);
        if(ids == ""){
            messageDanger("添加攻击端失败", "未选择攻击端!");
            $("#submit").removeAttr("disabled");
            return;
        }
        $.ajax({
            type : "POST",
            url : BasePath + "/ddosTaskTool/add.do",
            data : {
                'taskid' : ddostaskid,
                'ids' : ids
            },
            dataType : "json",
            success : function(data) {
                if (data.retCode == SUCCESS) {
                    successAlert();
                    location.href = BasePath + "/#/ddosTask4ToolInfo";
                }else{
                    messageDanger("添加攻击端失败", data.retMessage);
                }
                $("#submit").removeAttr("disabled");
            }
        });
    };
}]);
/**
 * 查看攻击端下的所有任务
 */
bracketCtrls.controller('ddosTool4TaskInfo', [ '$scope', function($scope, $http) {
    if(checkRole('#/ddosTool4TaskInfo,','ddosManage')){
        return;
    }
    $("#taskTool").html('<font size="3px;"color="#1D2939">'+sessionStorage.getItem("shefip4EditDdos")+'</font> 攻击端下的任务信息');
    var toolid = sessionStorage.getItem("id4DdosTaskTool");
    $('#datatable').bootstrapTable({
        method : 'post',
        url : BasePath + '/ddosTaskTool/queryTask.do?toolid='+toolid,
        cache : false,
        striped : true,
        sidePagination : 'server',
        pagination : true,
        pageSize : 10,
        pageList : [ 10, 25, 50, 100, 200 ],
        showColumns : true,
        showRefresh : true,
        minimumCountColumns : 2,
        onLoadError: SessionTimeOut, //处理过期
        columns : [ {
            field : 'name',
            title : '任务名称',
            align : 'center',
            valign : 'middle'
        }, {
            field : 'targetip',
            title : '目标地址',
            align : 'center',
            valign : 'middle'
        }, {
            field : 'starttime',
            title : '开始时间',
            align : 'center',
            valign : 'middle'
        }, {
            field : 'attacktime',
            title : '攻击时长',
            align : 'center',
            valign : 'middle'
        }, {
            field : 'attacktype',
            title : '攻击类型',
            align : 'center',
            valign : 'middle'
        }, {
            field : 'taskstate',
            title : '任务状态',
            align : 'center',
            valign : 'middle'
        }]
    });
} ]);
/**
 * 上传检测结果日志
 */
bracketCtrls.controller('upBoceLog',['$scope', function($scope, $http) {
    if(checkRole('#/upBoceLog,','taskManage')){
        return;
    }
    $scope.save = function() {
        $.ajaxFileUpload({
            url : BasePath + "/taskresult/upBoceLog.do",
            data : {},
            dataType : "json",
            secureuri: false, //是否需要安全协议，一般设置为false
            fileElementId: 'file1', //文件上传域的ID
            success : function(data) {
                if (data.retCode == SUCCESS) {
                    messageSuccess("操作成功", "结果已导出");
                }else{
                    messageDanger("根据拨测日志得到样本类型失败", data.retMessage);
                }
            }
        });
    };
} ]);
/**
 * 角色信息
 */
bracketCtrls.controller('roleInfo',['$scope',function($scope, $http) {
    if(checkRole('#/roleInfo,','sysManage')){
        return;
    }
    var columns = [ {
        field : 'name',
        title : '角色名称',
        align : 'center',
        valign : 'middle'
    }, {
        field : 'level',
        title : '级别',
        align : 'center',
        valign : 'middle'
    }, {
        field : 'createtime',
        title : '创建时间',
        align : 'center',
        valign : 'middle'
    } ];
    if(checkElement('editRole,') || checkElement('deleteRole,')){
        columns.push({
            title : '操作',
            align : 'center',
            valign : 'middle',
            formatter : operateFormatterForRole,
            events : operateEventsForRole
        });
    }
    if(checkElement('addRole,')){
        $('#addRole').attr("style","width: 110px;padding-bottom: 10px;display:block;");
    }
    if(checkElement('deleteRole,')){
        //删除角色
        $scope.del = function() {
            $.ajax({
                type : "POST",
                url  : BasePath+ "/role/deleteRole.do",
                data : {
                    'roleid' : sessionStorage.getItem("roleId")
                },
                dataType : "json",
                success : function(data) {
                    if (data.retCode == SUCCESS) {
                        successAlert();
                        $('#datatable').bootstrapTable('refresh',{url : BasePath+ '/role/queryRole.do'});
                    } else {
                        messageDanger("删除角色失败", data.retMessage);
                    }
                }
            });
        };
    }
    $('#datatable').bootstrapTable({
        method : 'post',
        url : BasePath + '/role/queryRole.do',
        cache : false,
        striped : true,
        sidePagination : 'server',
        pagination : true,
        pageSize : 10,
        pageList : [ 10, 25, 50, 100, 200 ],
        showColumns : true,
        showRefresh : true,
        minimumCountColumns : 2,
        onLoadError: SessionTimeOut, //处理过期
        columns : columns
    });
} ]);
/**
 * 创建角色
 */
bracketCtrls.controller('creatRole',['$scope',function($scope, $http) {
    if(checkRole('#/creatRole,','sysManage')){
        return;
    }
    $scope.save = function(roleInfo) {
        $("#submit").attr("disabled", true);
        $.ajax({
            type : "POST",
            url : BasePath + "/role/addRole.do",
            data : {
                'name' : roleInfo.name
            },
            dataType : "json",
            success : function(data) {
                if (data.retCode == SUCCESS) {
                    successAlert();
                    location.href = BasePath + "/#/roleInfo";
                }else{
                    messageDanger("创建角色失败", data.retMessage);
                }
                $("#submit").removeAttr("disabled");
            }
        });
    };
    $scope.reset = function() {
        $scope.roleInfo = {};
    };
} ]);
/**
 * 修改角色
 */
bracketCtrls.controller('editRole',['$scope',function($scope, $http) {
    if(checkRole('#/editRole,','sysManage')){
        return;
    }
    var id = sessionStorage.getItem("roleId");
    if(id == null || id == ""){
        location.href = BasePath + "/#/main";
        return;
    }
    $("#roleName").html('修改  <font size="3px;"color="#1D2939">'+sessionStorage.getItem("name")+'</font> 角色信息');
    $scope.roleInfo = {
        name : sessionStorage.getItem("name")
    };
    $scope.save = function(roleInfo) {
        $("#submit").attr("disabled", true);
        $.ajax({
            type : "POST",
            url : BasePath + "/role/editRole.do",
            data : {
                'id' : id,
                'name' : roleInfo.name
            },
            dataType : "json",
            success : function(data) {
                if (data.retCode == SUCCESS) {
                    successAlert();
                    location.href = BasePath + "/#/roleInfo";
                }else{
                    messageDanger("修改角色信息失败", data.retMessage);
                }
                $("#submit").removeAttr("disabled");
            }
        });

    };
    $scope.reset = function() {
        $scope.roleInfo = {
            name : sessionStorage.getItem("name")
        };
    };
} ]);
/**
 * 权限分配（zTree）roleAuthority.html
 */
bracketCtrls.controller('roleAuthority',['$scope',function($scope, $http) {
    if(checkRole('#/roleAuthority,','sysManage')){
        return;
    }
    /**ztree的参数配置，setting主要是设置一些tree的属性，是本地数据源，还是远程，动画效果，是否含有复选框等等**/
    var setting = {
        view: {
            expandSpeed: 300  //设置树展开的动画速度
        },
        data: {
            simpleData: {   //简单的数据源，一般开发中都是从数据库里读取，API有介绍，这里只是本地的
                enable: true,
                idKey: "id",  //id和pid，树的目录级别
                pIdKey: "pId",
                rootPId: 0   //根节点
            }
        },
        callback: {     /**回调函数的设置，随便写了两个**/
            beforeClick: beforeClick,
            onCheck: onCheck
        }
    };
    var setting1 = {
        check: { /**复选框**/
            enable: true,    //复选框开启
            chkboxType: {"Y":"ps", "N":"s"}    //被勾选时：关联父  关联子  取消时：关联子
        },
        view: {
            dblClickExpand: true,  //双击展开父节点的功能
            expandSpeed: 300  //设置树展开的动画速度
        },
        data: {
            simpleData: {   //简单的数据源，一般开发中都是从数据库里读取，API有介绍，这里只是本地的
                enable: true,
                idKey: "id",  //id和pid，树的目录级别
                pIdKey: "pId",
            }
        }
    };
    var roleid;
    function beforeClick(treeId, treeNode) {   //点击勾选按钮后面的执行这个事件
//		alert("beforeClick||"+treeNode.tId+"==>"+treeNode.name+"->"+treeNode.pId+"->"+treeNode.id);
        $("#ztreeid").hide();
        $('#submit').hide();
        roleid = treeNode.id;
        $("#roleMenutitle").text(treeNode.name+" 菜单分配情况");
        $.ajax({  //该角色所具有的菜单给zTree
            type : "POST",
            url : BasePath + "/menu/selectMenuByRoleid.do",
            data : {
                'roleid' : treeNode.id
            },
            dataType : "json",
            success : function(data) {
                $.fn.zTree.init($("#tree1"),setting1, data.menulist);
                $("#ztreeid").show();
                if(data.menulist.length > 0){
                    $('#submit').show();
                }
            }
        });
        $("#ztreeid").show();
    }
    function onCheck(e, treeId, treeNode) {    //点击勾选按钮执行这个事件
//		alert("onCheck||"+treeNode.tId+"==>"+treeNode.name+"->"+treeNode.pId+"->"+treeNode.id);
    }
    function createTree() {
        $.ajax({  //查询所有的角色给zTree
            type : "POST",
            url : BasePath + "/role/selectRole.do",
            data : {},
            dataType : "json",
            success : function(data) {
                $.fn.zTree.init($("#tree"),setting, data.rolelist);
            }
        });
    }
    $(document).ready(function(){  //初始化ztree对象
        createTree();
    });

    //保存
    $scope.save = function() {
        $('#submit').attr("disabled", true);
        var zTree = $.fn.zTree.getZTreeObj("tree1"); //获取tree1对象
        var nodes = zTree.getCheckedNodes(true);     //根据zTree这个对象的方法，获得被勾选的节点
        var str=",";
        for(var i=0;i<nodes.length;i++){
            str+= nodes[i].id+",";
        }
        var menuids = str.substring(1, str.length-1);
        $.ajax({
            type : "POST",
            url : BasePath + "/menu/addRoleAndMenu.do",
            data : {
                'roleid': roleid,
                'menuids' : menuids
            },
            dataType : "json",
            success : function(data) {
                if (data.retCode == SUCCESS) {
                    successAlert();
                }else{
                    messageDanger("角色分配菜单失败", data.retMessage);
                    location.href = BasePath + "/#/roleAuthority";
                }
                $("#submit").removeAttr("disabled");
            }
        });
    };
} ]);
/**
 * 企业信息
 */
bracketCtrls.controller('companyInfo',['$scope',function($scope, $http) {
    if(checkRole('#/companyInfo,','companyManage')){
        return;
    }
    var columns = [ {
        field : 'name',
        title : '企业名称',
        align : 'center',
        valign : 'middle'
    }, {
        field : 'taskNum',
        title : '可创建拨测任务数量(个)',
        align : 'center',
        valign : 'middle'
    },{
        field : 'samplenum',
        title : '可使用的样本数量(个)',
        align : 'center',
        valign : 'middle'
    }];
    if(checkElement('addCompany,')){
        $('#addCompany').attr("style","width: 110px;padding-bottom: 10px;display:block;");
    }
    if(checkElement('editCompany,') || checkElement('manageTargetByCompany,')){
        columns.push({
            title : '操作',
            align : 'center',
            valign : 'middle',
            formatter : operateFormatterForCompany,
            events : operateEventsForCompany
        });
    }
    $('#datatable').bootstrapTable({
        method : 'post',
        url : BasePath + '/company/query.do',
        cache : false,
        striped : true,
        sidePagination : 'server',
        pagination : true,
        pageSize : 10,
        pageList : [ 10, 25, 50, 100, 200 ],
        showColumns : true,
        showRefresh : true,
        minimumCountColumns : 2,
        onLoadError: SessionTimeOut, //处理过期
        columns : columns
    });
} ]);
/**
 * 创建企业
 */
bracketCtrls.controller('createCompany',['$scope',function($scope, $http) {
    if(checkRole('#/createCompany,','companyManage')){
        return;
    }
    var output = [];
    $.ajax({
        type : "POST",
        url : BasePath + "/target/queryTargetByState.do",
        data : {},
        dataType : "json",
        success : function(data) {
            if (data.retCode == SUCCESS) {
                var list = data.result;
                for ( var i = 0; i < list.length; i++) {
                    output.push('<option value="' + list[i].id + '">'
                        + list[i].location +' - '+list[i].operator+' - '+list[i].ip +':'+list[i].targetport+ '</option>');
                }
                $(".select2").html(output.join(''));
                $(".select2").select2();
                $(".select2").width("100%");
                $("#onload").attr("style", "display:none;");
                $("#panel-body").attr("style", "display:block;");
            } else {
                messageDanger("靶机列表暂无数据", data.retMessage);
                location.href = BasePath + "/#/companyInfo";
            }
        }
    });
    var count;
    var nomalSampleCount;
    var likeSampleCount;
    var evilSampleCount;
    $.ajax({               //各种样本数量
        type : "POST",
        url : BasePath + "/sample/addSampleBankRandomMax.do",
        data :{
            'type': 'cmcc&virus'
        },
        dataType : "json",
        success : function(data) {
            if (data.retCode == SUCCESS) {
                var map = data.result; //不同样本类型的样本数量
                var typeStr = "可以使用的样本";
                count = Number(map.sampleTotalCount); //总的数量
                evilSampleCount = Number(map.evilSampleCount); //恶意
                nomalSampleCount = Number(map.nomalSampleCount); //正常
                likeSampleCount = Number(map.likeSampleCount);   //疑似
                $("#msg").html("* 抽取数量至少为1，"+typeStr+"("+count+"个)"+"下的恶意样本总数为"+evilSampleCount+"个");
                $("#msg1").html("可以不填默认为0，"+typeStr+"("+count+"个)"+"下的正常样本总数为"+nomalSampleCount+"个");
                $("#msg2").html("可以不填默认为0，"+typeStr+"("+count+"个)"+"下的疑似样本总数为"+likeSampleCount+"个");
            } else {
                messageDanger("暂无样本数据", data.retMessage);
                location.href = BasePath + "/#/companyInfo";
            }
        }
    });
    $scope.save = function(companyInfo) {
        var evilNum = Number(companyInfo.evilSampleNum);  //恶意样本数量
        var nomalNum = Number($("#nomalSampleNum").val()); //取得输入框里的正常样本值
        var likeNum = Number($("#likeSampleNum").val());   //取得输入框里的疑似样本值
        if(nomalNum==""||nomalNum==null){
            nomalNum = 0;
        }
        if(likeNum==""||likeNum==null){
            likeNum = 0;
        }
        if(nomalNum > nomalSampleCount){
            nomalNum = nomalSampleCount;
        }
        if(likeNum > likeSampleCount){
            likeNum = likeSampleCount;
        }
        if(evilNum > evilSampleCount){
            evilNum = count;
        }
        $("#submit").attr("disabled", true);
        var ids = "";
        $(".select2 option:selected").each(function() {
            ids += $(this).attr("value") + ",";
        });
        ids = ids.substring(0, ids.length - 1);
        if(ids == ""){
            messageDanger("创建企业失败", "未选择靶机!");
            $("#submit").removeAttr("disabled");
            return ;
        }
        $.ajax({
            type : "POST",
            url : BasePath + "/company/add.do",
            data : {
                'name':companyInfo.name,
                'taskNum':companyInfo.taskNum,
                'targetIds':ids,
                'evilNum':evilNum,
                'nomalNum':nomalNum,
                'likeNum':likeNum
            },
            dataType : "json",
            success : function(data) {
                if (data.retCode == SUCCESS) {
                    successAlert();
                    location.href = BasePath+ "/#/companyInfo";
                } else{
                    messageDanger("创建企业失败", data.retMessage);
                }
                $("#submit").removeAttr("disabled");
            }
        });
    };
    $scope.reset = function() {
        $scope.companyInfo = {
        };
    };
} ]);
/**
 * 修改企业信息
 */
bracketCtrls.controller('editCompany',['$scope',function($scope, $http) {
    if(checkRole('#/editCompany,','companyManage')){
        return;
    }
    var id = sessionStorage.getItem("companyId");
    if(id == null || id == ""){
        location.href = BasePath + "/#/main";
        return;
    }
    $("#companyName").html('修改  <font size="3px;"color="#1D2939">'+sessionStorage.getItem("companyName")+'</font> 企业信息');
    $("#numberid").html('该企业目前已创建的任务个数为  <font size="3px;"color="#1D2939">'
        +sessionStorage.getItem("companyUsedTaskNum")+"</font>个"); //显示该企业使用的任务数量
    $scope.companyInfo = {
        name : sessionStorage.getItem("companyName"),
        taskNum : Number(sessionStorage.getItem("companyTaskNum"))
    };
    $scope.save = function(companyInfo) {
        $.ajax({
            type : "POST",
            url : BasePath + "/company/update.do",
            data : {'name':companyInfo.name,'taskNum':companyInfo.taskNum,'id':id},
            dataType : "json",
            success : function(data) {
                if (data.retCode == SUCCESS) {
                    successAlert();
                    location.href = BasePath+ "/#/companyInfo";
                } else{
                    messageDanger("修改企业信息失败", data.retMessage);
                }
                $("#submit").removeAttr("disabled");
            }
        });
    };
    $scope.reset = function() {
        $scope.companyInfo = {
            name : sessionStorage.getItem("companyName"),
            taskNum : Number(sessionStorage.getItem("companyTaskNum"))
        };
    };
} ]);
/**
 * 管理企业可用靶机
 */
bracketCtrls.controller('company4TargetInfo',['$scope',function($scope, $http) {
    if(checkRole('#/company4TargetInfo,','companyManage')){
        return;
    }
    var id = sessionStorage.getItem("companyId");
    var targetIds = sessionStorage.getItem("companyTargetIds");
    if(id == null || id == "" || targetIds == null){
        location.href = BasePath + "/#/main";
        return;
    }
    $("#companyName").html('<font size="3px;"color="#1D2939">'+sessionStorage.getItem("companyName")+'</font> 企业下可用靶机信息');
    var columns = [{
        field : 'location',
        title : '地区',
        align : 'center',
        valign : 'middle'
    }, {
        field : 'operator',
        title : '运营商',
        align : 'center',
        valign : 'middle'
    }, {
        field : 'ip',
        title : 'IP地址',
        align : 'center',
        valign : 'middle'
    }, {
        field : 'targetport',
        title : '端口',
        align : 'center',
        valign : 'middle'
    }, {
        field : 'ftp',
        title : 'FTP服务',
        align : 'center',
        valign : 'middle'
    }, {
        field : 'state',
        title : '启用/禁用',
        align : 'center',
        valign : 'middle'
    } ];
    if(checkElement('addTargetByCompany,')){
        $('#addTargetByCompany').attr("style","style","width: 110px;padding-bottom: 10px;display:block;");
    }
    if(checkElement('deleteTargetByCompany,')){
        columns.push({
            title : '操作',
            align : 'center',
            valign : 'middle',
            formatter : operateFormatterForCompanyTarget,
            events : operateEventsForCompanyTarget
        });
        //删除靶机
        $scope.del = function() {
            var targetId = sessionStorage.getItem("company4TargetId");
            var targetArray = targetIds.split(",");
            var newTargetIds = "";
            for ( var x in targetArray) {
                if(targetArray[x] != targetId){
                    newTargetIds = newTargetIds + targetArray[x] + ",";
                }
            }
            if(newTargetIds != ""){
                newTargetIds = newTargetIds.substring(0, newTargetIds.length - 1);
            }
            $.ajax({
                type : "POST",
                url  : BasePath+ "/company/update.do",
                data : {
                    'id' : id,
                    'targetIds' : newTargetIds
                },
                dataType : "json",
                success : function(data) {
                    if (data.retCode == SUCCESS) {
                        successAlert();
                        targetIds = newTargetIds ;
                        sessionStorage.setItem("companyTargetIds", targetIds);
                        $('#datatable').bootstrapTable('refresh',{url : BasePath+ '/target/queryTargetByIds.do?ids='+targetIds});
                    } else {
                        messageDanger("删除靶机失败", data.retMessage);
                    }
                }
            });
        };
    }
    $('#datatable').bootstrapTable({
        method : 'post',
        url : BasePath + '/target/queryTargetByIds.do?ids='+targetIds,
        cache : false,
        striped : true,
        sidePagination : 'server',
        pagination : false,
        pageSize : 10,
        pageList : [ 10, 25, 50, 100, 200 ],
        showColumns : true,
        showRefresh : true,
        onLoadError: SessionTimeOut, //处理过期
        columns : columns
    });
} ]);
/**
 * 添加企业可用靶机
 */
bracketCtrls.controller('createTarget4Company',['$scope',function($scope, $http) {
    if(checkRole('#/createTarget4Company,','companyManage')){
        return;
    }
    var companyId = sessionStorage.getItem("companyId");
    var targetIds = sessionStorage.getItem("companyTargetIds");
    if(companyId == null || companyId == "" || targetIds == null){
        location.href = BasePath + "/#/main";
        return;
    }
    $("#companyName").html('<font size="3px;"color="#1D2939">'+sessionStorage.getItem("companyName")+'</font> 企业下添加靶机');
    var output = [];
    $.ajax({
        type : "POST",
        url : BasePath + "/target/queryTargetByState.do",
        data : {'ids' : targetIds},
        dataType : "json",
        success : function(data) {
            if (data.retCode == SUCCESS) {
                var list = data.result;
                for ( var i = 0; i < list.length; i++) {
                    output.push('<option value="' + list[i].id + '">'
                        + list[i].location +' - '+list[i].operator+' - '+list[i].ip +':'+list[i].targetport+ '</option>');
                }
                $(".select2").html(output.join(''));
                $(".select2").select2();
                $(".select2").width("100%");
                $("#onload").attr("style", "display:none;");
                $("#panel-body").attr("style", "display:block;");
            } else {
                messageDanger("靶机列表暂无数据", data.retMessage);
                location.href = BasePath + "/#/company4TargetInfo";
            }
        }
    });
    $scope.save = function(companyInfo) {
        var ids = "";
        $(".select2 option:selected").each(function() {
            ids += $(this).attr("value") + ",";
        });
        if(ids == ""){
            messageDanger("添加靶机失败", "未选择靶机!");
            return ;
        }
        if(targetIds != ""){
            ids = ids+","+targetIds;
        }else{
            ids = ids.substring(0, ids.length - 1);
        }
        $("#submit").attr("disabled", true);
        $.ajax({
            type : "POST",
            url : BasePath + "/company/update.do",
            data : {'id':companyId,'targetIds':ids},
            dataType : "json",
            success : function(data) {
                if (data.retCode == SUCCESS) {
                    sessionStorage.setItem("companyTargetIds", ids);
                    successAlert();
                    location.href = BasePath+ "/#/company4TargetInfo";
                } else{
                    messageDanger("添加靶机失败", data.retMessage);
                }
                $("#submit").removeAttr("disabled");
            }
        });
    };
} ]);
/**
 * 管理企业可用样本
 */
bracketCtrls.controller('company4SampleInfo',['$scope',function($scope, $http) {
    if(checkRole('#/company4SampleInfo,','companyManage')){
        return;
    }
    var id = sessionStorage.getItem("companyId");
    if(id == null || id == ""){
        location.href = BasePath + "/#/main";
        return;
    }
    $("#companyName").html('<font size="3px;"color="#1D2939">'+sessionStorage.getItem("companyName")+'</font> 企业下可用样本信息');
    var columns = [{
        field : 'name',
        title : '样本名',
        align : 'center',
        valign : 'middle'
    }, {
        field : 'md5',
        title : 'MD5',
        align : 'center',
        valign : 'middle'
    }, {
        field : 'type',
        title : '样本类型',
        align : 'center',
        valign : 'middle'
    }, {
        field : 'type1',
        title : '样本种类',
        align : 'center',
        valign : 'middle'
    } , {
        field : 'companyname',
        title : '公司名称',
        align : 'center',
        valign : 'middle'
    } ];
    if(checkElement('addSampleByCompany,')){
        $('#addSampleByCompany').attr("style","style","width: 110px;padding-bottom: 10px;display:block;");
    }
    if(checkElement('deleteSampleByCompany,')){
        columns.push({
            title : '操作',
            align : 'center',
            valign : 'middle',
            formatter : operateFormatterForCompanySample,
            events : operateEventsForCompanySample
        });
        //删除样本
        $scope.del = function() {
            var sampleId = sessionStorage.getItem("company4SampleId");
            $.ajax({
                type : "POST",
                url  : BasePath+ "/companySample/delete.do",
                data : {
                    'companyId' : id,
                    'sampleId' : sampleId
                },
                dataType : "json",
                success : function(data) {
                    if (data.retCode == SUCCESS) {
                        successAlert();
                        $('#datatable').bootstrapTable('refresh',{url : BasePath+ '/companySample/query.do?companyId='+id});
                    } else if(data.retCode == '0050') {
                        messageDanger("删除样本失败", data.result);
                    } else {
                        messageDanger("删除样本失败", data.retMessage);
                    }
                }
            });
        };
    }
    $('#datatable').bootstrapTable({
        method : 'post',
        url : BasePath + '/companySample/query.do?companyId='+id,
        cache : false,
        striped : true,
        sidePagination : 'server',
        pagination : true,
        pageSize : 10,
        pageList : [ 10, 25, 50, 100, 200 ],
        showColumns : true,
        showRefresh : true,
        onLoadError: SessionTimeOut, //处理过期
        columns : columns
    });
} ]);
/**
 * 添加企业可用样本
 */
bracketCtrls.controller('createSample4Company',['$scope',function($scope, $http) {
    if(checkRole('#/createSample4Company,','companyManage')){
        return;
    }
    var companyId = sessionStorage.getItem("companyId");
    if(companyId == null || companyId == ""){
        location.href = BasePath + "/#/main";
        return;
    }
    $("#companyName").html('<font size="3px;"color="#1D2939">'+sessionStorage.getItem("companyName")+'</font> 企业下添加样本');
    var output = [];
    $.ajax({
        type : "POST",
        url : BasePath + "/companySample/querySample.do",
        data : {'companyId' : companyId},
        dataType : "json",
        success : function(data) {
            if (data.retCode == SUCCESS) {
                var list = data.result;
                for ( var i = 0; i < list.length; i++) {
                    output.push('<option value="' + list[i].sampleid + '">'
                        + list[i].name +' - '+list[i].type+' - '+list[i].type1 + '</option>');
                }
                $(".select2").html(output.join(''));
                $(".select2").select2();
                $(".select2").width("100%");
                $("#onload").attr("style", "display:none;");
                $("#panel-body").attr("style", "display:block;");
            } else {
                messageDanger("样本列表暂无数据", data.retMessage);
                location.href = BasePath + "/#/company4SampleInfo";
            }
        }
    });
    $scope.save = function() {
        var ids = "";
        $(".select2 option:selected").each(function() {
            ids += $(this).attr("value") + ",";
        });
        if(ids == ""){
            messageDanger("添加样本失败", "未选择样本!");
            return ;
        }
        ids = ids.substring(0, ids.length - 1);
        $("#submit").attr("disabled", true);
        $.ajax({
            type : "POST",
            url : BasePath + "/companySample/add.do",
            data : {'companyId':companyId,'sampleIds':ids},
            dataType : "json",
            success : function(data) {
                if (data.retCode == SUCCESS) {
                    successAlert();
                    location.href = BasePath+ "/#/company4SampleInfo";
                } else{
                    messageDanger("添加样本失败", data.retMessage);
                }
                $("#submit").removeAttr("disabled");
            }
        });
    };
} ]);
/**
 * 攻击端实时监控
 */
bracketCtrls.controller('supervisory4Ddos', [ '$scope', function($scope, $http) {
    if(checkRole('#/supervisory4Ddos,','ddosManage')){
        return;
    }
    var ip = sessionStorage.getItem("shefip4SupervisoryDdos");
    if(ip == "" || ip == null){
        location.href = BasePath + "/#/main";
        return;
    }
    $('#name').html('监控IP为  <font size="3px;"color="#1D2939">'+ip+'</font> 的攻击端');
    Highcharts.setOptions({
        global: {
            useUTC: false
        }
    });
    function activeLastPointToolip(chart) {
        var points = chart.series[0].points;
        chart.tooltip.refresh(points[points.length -1]);
    }
    var recvSeries,recvChart,
        sendSeries,sendChart,
        cpuSeries,cpuChart;
    $('#recv-container').highcharts({
        chart: {
            type: 'spline',
            animation: Highcharts.svg, // don't animate in old IE
            marginRight: 10,
            events: {
                load: function () {
                    // set up the updating of the chart each second
                    recvSeries = this.series[0];
                    recvChart = this;
                }
            }
        },
        credits: {
            enabled: false   //右下角不显示LOGO
        },
        title: {
            text: '流入流量实时速率'
        },
        xAxis: {
            type: 'datetime',
            tickPixelInterval: 150
        },
        yAxis: {
            title: {
                text: '单位: kBps'
            },
            plotLines: [{
                value: 0,
                width: 1,
                color: '#808080'
            }]
        },
        tooltip: {
            formatter: function () {
                return '<b>' + this.series.name + '</b><br/>' +
                    Highcharts.dateFormat('%Y-%m-%d %H:%M:%S', this.x) + '<br/>' +
                    Highcharts.numberFormat(this.y, 2);
            }
        },
        legend: {
            enabled: false
        },
        exporting: {
            enabled: false
        },
        series: [{
            name: '流入流量速率',
            data: (function () {
                // generate an array of random data
                var data = [],
                    time = (new Date()).getTime(),
                    i;
                for (i = -9; i <= 0; i += 1) {
                    data.push({
                        x: time + i * 5000,
                        y: 0
                    });
                }
                return data;
            }())
        }]
    }, function(c) {
        activeLastPointToolip(c)
    });

    $('#send-container').highcharts({
        chart: {
            type: 'spline',
            animation: Highcharts.svg, // don't animate in old IE
            marginRight: 10,
            events: {
                load: function () {
                    // set up the updating of the chart each second
                    sendSeries = this.series[0];
                    sendChart = this;
                }
            }
        },
        credits: {
            enabled: false   //右下角不显示LOGO
        },
        title: {
            text: '流出流量实时速率'
        },
        xAxis: {
            type: 'datetime',
            tickPixelInterval: 150
        },
        yAxis: {
            title: {
                text: '单位: kBps'
            },
            plotLines: [{
                value: 0,
                width: 1,
                color: '#808080'
            }]
        },
        tooltip: {
            formatter: function () {
                return '<b>' + this.series.name + '</b><br/>' +
                    Highcharts.dateFormat('%Y-%m-%d %H:%M:%S', this.x) + '<br/>' +
                    Highcharts.numberFormat(this.y, 2);
            }
        },
        legend: {
            enabled: false
        },
        exporting: {
            enabled: false
        },
        series: [{
            name: '流出流量速率',
            data: (function () {
                // generate an array of random data
                var data = [],
                    time = (new Date()).getTime(),
                    i;
                for (i = -9; i <= 0; i += 1) {
                    data.push({
                        x: time + i * 5000,
                        y: 0
                    });
                }
                return data;
            }())
        }]
    }, function(c) {
        activeLastPointToolip(c)
    });

    $('#cpu-container').highcharts({
        chart: {
            type: 'spline',
            animation: Highcharts.svg, // don't animate in old IE
            marginRight: 10,
            events: {
                load: function () {
                    // set up the updating of the chart each second
                    cpuSeries = this.series[0];
                    cpuChart = this;
                }
            }
        },
        credits: {
            enabled: false   //右下角不显示LOGO
        },
        title: {
            text: 'CPU实时使用率'
        },
        xAxis: {
            type: 'datetime',
            tickPixelInterval: 150
        },
        yAxis: {
            title: {
                text: '单位: %'
            },
            plotLines: [{
                value: 0,
                width: 1,
                color: '#808080'
            }]
        },
        tooltip: {
            formatter: function () {
                return '<b>' + this.series.name + '</b><br/>' +
                    Highcharts.dateFormat('%Y-%m-%d %H:%M:%S', this.x) + '<br/>' +
                    Highcharts.numberFormat(this.y, 2);
            }
        },
        legend: {
            enabled: false
        },
        exporting: {
            enabled: false
        },
        series: [{
            name: 'CPU实时使用率',
            data: (function () {
                // generate an array of random data
                var data = [],
                    time = (new Date()).getTime(),
                    i;
                for (i = -9; i <= 0; i += 1) {
                    data.push({
                        x: time + i * 5000,
                        y: 0
                    });
                }
                return data;
            }())
        }]
    }, function(c) {
        activeLastPointToolip(c)
    });

    time = window.setInterval(function () {
        $.ajax({
            type : "POST",
            url : BasePath + "/DdosTool/supervisory.do",
            data : {'ip':ip},
            dataType : "json",
            success : function(data) {
                var x = (new Date()).getTime(), // current time
                    y = data.result.recv;
                recvSeries.addPoint([x, y], true, true);
                activeLastPointToolip(recvChart);
                y = data.result.send;
                sendSeries.addPoint([x, y], true, true);
                activeLastPointToolip(sendChart);
                y = data.result.cpu;
                cpuSeries.addPoint([x, y], true, true);
                activeLastPointToolip(cpuChart);
            }
        });
    }, 5000);
} ]);
/**
 * 攻击端历史监控
 */
bracketCtrls.controller('historySupervisory4Ddos', [ '$scope', function($scope, $http) {
    if(checkRole('#/historySupervisory4Ddos,','ddosManage')){
        return;
    }
    var ip = sessionStorage.getItem("shefip4SupervisoryDdos");
    if(ip == "" || ip == null){
        location.href = BasePath + "/#/main";
        return;
    }
    $('#name').html('IP为  <font size="3px;"color="#1D2939">'+ip+'</font> 的攻击端历史监控信息');
    var list,count,size,pageNum=1,remainder,length=50;
    var baseHtmlStr = '<table class="table table-hover table-striped table-bordered"><thead><tr><th>CPU使用率</th>' +
        '<th>流入流量速率</th><th>流出流量速率</th><th>日期( 日-月 时间 )</th></tr></thead><tboby>';
    $.ajax({
        type : "POST",
        url : BasePath + "/DdosTool/supervisory.do",
        data : {'ip':ip,'type':'history'},
        dataType : "json",
        success : function(data) {
            $('#onload').hide();
            $('#onboby').show();
            if(data.retCode == "0030"){
                var htmlStr = baseHtmlStr + '<tr class="no-records-found"><td colspan="4">没有找到匹配的记录</td></tr></tboby></table>';
                $('#content').html(htmlStr);
                $('th').attr("style","text-align: center; vertical-align: middle; ");
                $('td').attr("style","text-align: center; vertical-align: middle; ");
            }else{
                list = data.result;
                count = list.length;
                size = parseInt(count/length);
                remainder = count%length;
                var optionStr = "";
                var temp = size;
                if(size != 0){
                    if(remainder > 0){
                        temp = size + 1;
                    }
                    for(var i=1;i<=temp;i++){
                        if(i != pageNum){
                            optionStr = optionStr + '<option value="'+i+'">' + i + '</option>';
                        }else{
                            optionStr = optionStr + '<option value="'+pageNum+'" selected = "selected">'+pageNum+'</option>';
                        }
                    }
                }else{
                    optionStr = '<option value="1" selected = "selected">1</option>';
                }
                $('.mainpanel').attr("style","min-height:1000px;");
                refresh(pageNum);
                $('#pageInfo').show();
                $('#page').html(optionStr);
                $('#count').html(count);
            }
        }
    });
    $('#page').change(function () {
        pageNum = Number($('#page').val());
        refresh(pageNum);
    });
    function refresh(pageNum) {
        var htmlStr = baseHtmlStr;
        if(size >= pageNum){
            for(var i=(pageNum -1)*length;i<pageNum*length;i++){
                htmlStr = htmlStr + '<tr><td>'+list[i].cpu+'</td><td>'+list[i].recv+'</td><td>'+list[i].send+'</td>'
                    +'<td>'+list[i].time+'</td></tr>'
            }
        }else{
            for(var i=(pageNum -1)*length;i<count;i++){
                htmlStr = htmlStr + '<tr><td>'+list[i].cpu+'</td><td>'+list[i].recv+'</td><td>'+list[i].send+'</td>'
                    +'<td>'+list[i].time+'</td></tr>'
            }
        }
        htmlStr = htmlStr + '</tboby></table>';
        $('#content').html(htmlStr);
        $('th').attr("style","text-align: center; vertical-align: middle; ");
        $('td').attr("style","text-align: center; vertical-align: middle; ");
    }
} ]);